diff --git a/Classes/DataProvider/DataProvider.php b/Classes/DataProvider/DataProvider.php index de70aa02..4edcaf45 100644 --- a/Classes/DataProvider/DataProvider.php +++ b/Classes/DataProvider/DataProvider.php @@ -42,7 +42,7 @@ class DataProvider implements DataProviderInterface, ClassLoadingInterface, Sing /** * @var IdentityProviderInterface */ - private $identityProvider; + protected $identityProvider; /** * Data Provider constructor @@ -144,8 +144,7 @@ public function createModel(array $data, ResourceType $resourceType) return $this->getEmptyModelForResourceType($resourceType); } - // It is possible to insert Models with a defined UID - // If a UID is given save and remove it from the data array + // It is **not** allowed to insert Models with a defined UID if (isset($data['__identity']) && $data['__identity']) { return new \UnexpectedValueException('Invalid property "__identity"'); } elseif (isset($data['uid']) && $data['uid']) { @@ -160,7 +159,16 @@ public function createModel(array $data, ResourceType $resourceType) public function getModelProperty($model, $propertyKey) { - return $this->getModelData($model->_getProperty($propertyKey)); + if ($model instanceof DomainObjectInterface) { + return $this->getModelData($model->_getProperty($propertyKey)); + } + + $getter = 'get' . ucfirst($propertyKey); + if (is_callable([$model, $getter])) { + return $this->getModelData($model->$getter()); + } + + return null; } public function saveModel($model, ResourceType $resourceType) diff --git a/Classes/DataProvider/DataProviderInterface.php b/Classes/DataProvider/DataProviderInterface.php index 88c3b619..f93cb0a2 100644 --- a/Classes/DataProvider/DataProviderInterface.php +++ b/Classes/DataProvider/DataProviderInterface.php @@ -38,7 +38,9 @@ public function fetchModel($identifier, ResourceType $resourceType); /** * Create a new Domain Model with the given data * - * Even if the data contains an identifier, the existing model will **not** be loaded + * Implementations are free to decide if identifiers are accepted (e.g. an exception will be thrown for Extbase + * Models if the property `uid` or `__identity` is given. `Virtual Objects` on the other hand accept identifier + * properties) * * @param array $data Data of the new model * @param ResourceType $resourceType API resource type to get the repository for diff --git a/Classes/DataProvider/VirtualObjectDataProvider.php b/Classes/DataProvider/VirtualObjectDataProvider.php index e61733b5..ca9333e7 100644 --- a/Classes/DataProvider/VirtualObjectDataProvider.php +++ b/Classes/DataProvider/VirtualObjectDataProvider.php @@ -83,29 +83,7 @@ public function createModel(array $data, ResourceType $resourceType) return $this->getEmptyModelForResourceType($resourceType); } - // It is possible to insert Models with a defined UID - // If a UID is given save and remove it from the data array - $uid = null; - //if (isset($data['__identity']) && $data['__identity']) { - // // Load the UID of the existing model - // $uid = $this->getUidOfModelWithIdentityForResourceType($data['__identity'], $resourceType); - //} elseif (isset($data['uid']) && $data['uid']) { - // $uid = $data['uid']; - //} - //if ($uid) { - // unset($data['__identity']); - // unset($data['uid']); - //} - - // Get a fresh model - $model = $this->convertIntoModel($data, $resourceType); - - if ($uid !== null) { - // Set the saved identifier - $model->_setProperty('uid', $uid); - } - - return $model; + return $this->convertIntoModel($data, $resourceType); } public function getRepositoryClassForResourceType(ResourceType $resourceType)