VersionPress\Storages\MetaEntityStorage::save PHP Method

save() public method

public save ( $data )
    public function save($data)
    {
        if (!$this->shouldBeSaved($data)) {
            return null;
        }
        $oldParent = $this->parentStorage->loadEntity($data[$this->parentReferenceName], null);
        $oldEntity = $this->extractEntityFromParentByVpId($oldParent, $data['vp_id']);
        $transformedData = $this->transformToParentEntityField($data);
        $this->lastVpId = $data['vp_id'];
        $this->parentStorage->save($transformedData);
        $newParent = $this->parentStorage->loadEntity($data[$this->parentReferenceName], null);
        $newEntity = $this->extractEntityFromParentByVpId($newParent, $data['vp_id']);
        if ($oldEntity == $newEntity) {
            return null;
        }
        if (!$oldEntity) {
            $action = 'create';
        } else {
            $action = 'edit';
        }
        return $this->createChangeInfoWithParentEntity($oldEntity, $newEntity, $oldParent, $newParent, $action);
    }

Usage Example

 /**
  * @test
  */
 public function loadAllReturnsOnlyOriginalEntities()
 {
     $this->parentStorage->save($this->testingParentEntity);
     $this->storage->save($this->testingMetaEntity);
     $loadedPostMeta = $this->storage->loadAll();
     $this->assertTrue(count($loadedPostMeta) === 1);
     $this->assertEquals($this->testingMetaEntity, reset($loadedPostMeta));
 }
All Usage Examples Of VersionPress\Storages\MetaEntityStorage::save