commit 03ef183e1cc48995a1ea1d654db8b5019e7970e7 Author: Wolfgang Ziegler // fago Date: Thu Sep 4 16:05:59 2014 +0200 Adressed berdir review. diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/Entity.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/Entity.php index 2b0251f..f199a4f 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/Entity.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/Entity.php @@ -79,47 +79,54 @@ public function setValue($entity, $notify = TRUE) { * {@inheritdoc} */ public function get($property_name) { - if (isset($this->entity) && $this->entity instanceof ContentEntityInterface) { - return $this->entity->get($property_name); + if (!isset($this->entity)) { + throw new MissingDataException(String::format('Unable to get property @name as no entity has been provided.', array('@name' => $property_name))); } - // @todo: Add support for config entities. - throw new MissingDataException(String::format('Unable to get property @name as no entity has been provided.', array('@name' => $property_name))); + if (!$this->entity instanceof ContentEntityInterface) { + // @todo: Add support for config entities. + throw new \InvalidArgumentException(String::format('Unable to get unknown property @name.', array('@name' => $property_name))); + } + // This will throw an exception for unknown fields. + return $this->entity->get($property_name); } /** * {@inheritdoc} */ public function set($property_name, $value, $notify = TRUE) { - if (isset($this->entity) && $this->entity instanceof ContentEntityInterface) { - $property = $this->entity->set($property_name, $value); - // Notify the parent of any changes. - if ($notify && isset($this->parent)) { - $this->parent->onChange($this->name); - } - return $property; + if (!isset($this->entity)) { + throw new MissingDataException(String::format('Unable to set property @name as no entity has been provided.', array('@name' => $property_name))); + } + if (!$this->entity instanceof ContentEntityInterface) { + // @todo: Add support for config entities. + throw new \InvalidArgumentException(String::format('Unable to set unknown property @name.', array('@name' => $property_name))); } - // @todo: Add support for config entities. - throw new MissingDataException(String::format('Unable to set property @name as no entity has been provided.', array('@name' => $property_name))); + // This will throw an exception for unknown fields. + return $this->entity->set($property_name, $value, $notify); } /** * {@inheritdoc} */ public function getProperties($include_computed = FALSE) { - if (isset($this->entity)) { - return $this->entity->getFields($include_computed); + if (!isset($this->entity)) { + throw new MissingDataException(String::format('Unable to get properties as no entity has been provided.')); } - throw new MissingDataException(String::format('Unable to get properties as no entity has been provided.')); + if (!$this->entity instanceof ContentEntityInterface) { + // @todo: Add support for config entities. + return array(); + } + return $this->entity->getFields($include_computed); } /** * {@inheritdoc} */ public function toArray() { - if (isset($this->entity)) { - return $this->entity->toArray(); + if (!isset($this->entity)) { + throw new MissingDataException(String::format('Unable to get property values as no entity has been provided.')); } - throw new MissingDataException(String::format('Unable to get property values as no entity has been provided.')); + return $this->entity->toArray(); } /** diff --git a/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php b/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php index fcd371d..6bc55d2 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php +++ b/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraintValidator.php @@ -23,7 +23,9 @@ public function validate($typed_entity, Constraint $constraint) { if (!isset($typed_entity)) { return; } - // @todo: Work over how metadata unwraps typed data or now. + // The constraint is used on both entity references and typed data entity + // objects. While entities are not automatically unwrapped, entity + // references are. $entity = $typed_entity instanceof TypedDataInterface ? $typed_entity->getValue() : $typed_entity; if (!in_array($entity->bundle(), $constraint->getBundleOption())) { $this->context->addViolation($constraint->message, array('%bundle' => implode(', ', $constraint->getBundleOption()))); diff --git a/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraintValidator.php b/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraintValidator.php index 4aac0aa..a307b24 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraintValidator.php +++ b/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraintValidator.php @@ -23,7 +23,9 @@ public function validate($typed_entity, Constraint $constraint) { if (!isset($typed_entity)) { return; } - // @todo: Work over how metadata unwraps typed data or now. + // The constraint is used on both entity references and typed data entity + // objects. While entities are not automatically unwrapped, entity + // references are. $entity = $typed_entity instanceof TypedDataInterface ? $typed_entity->getValue() : $typed_entity; /** @var $entity \Drupal\Core\Entity\EntityInterface */ if ($entity->getEntityTypeId() != $constraint->type) { diff --git a/core/lib/Drupal/Core/TypedData/ComplexDataInterface.php b/core/lib/Drupal/Core/TypedData/ComplexDataInterface.php index 7b8895a..2e5dfd6 100644 --- a/core/lib/Drupal/Core/TypedData/ComplexDataInterface.php +++ b/core/lib/Drupal/Core/TypedData/ComplexDataInterface.php @@ -31,13 +31,13 @@ * @param $property_name * The name of the property to get; e.g., 'title' or 'name'. * + * @return \Drupal\Core\TypedData\TypedDataInterface + * The property object. + * * @throws \InvalidArgumentException * If an invalid property name is given. * @throws \Drupal\Core\TypedData\MissingDataException * If the complex data structure is unset and no property can be created. - * - * @return \Drupal\Core\TypedData\TypedDataInterface - * The property object. */ public function get($property_name); @@ -53,13 +53,13 @@ public function get($property_name); * TRUE. If the update stems from a parent object, set it to FALSE to avoid * being notified again. * + * @return \Drupal\Core\TypedData\TypedDataInterface + * The property object. + * * @throws \InvalidArgumentException * If the specified property does not exist. * @throws \Drupal\Core\TypedData\MissingDataException * If the complex data structure is unset and no property can be set. - * - * @return \Drupal\Core\TypedData\TypedDataInterface - * The property object. */ public function set($property_name, $value, $notify = TRUE); @@ -69,12 +69,12 @@ public function set($property_name, $value, $notify = TRUE); * @param bool $include_computed * If set to TRUE, computed properties are included. Defaults to FALSE. * - * @throws \Drupal\Core\TypedData\MissingDataException - * If the complex data structure is unset and no property can be created. - * * @return \Drupal\Core\TypedData\TypedDataInterface[] * An array of property objects implementing the TypedDataInterface, keyed * by property name. + * + * @throws \Drupal\Core\TypedData\MissingDataException + * If the complex data structure is unset and no property can be created. */ public function getProperties($include_computed = FALSE); @@ -84,11 +84,11 @@ public function getProperties($include_computed = FALSE); * Gets an array of plain property values including all not-computed * properties. * - * @throws \Drupal\Core\TypedData\MissingDataException - * If the complex data structure is unset and no property can be created. - * * @return array * An array of property values, keyed by property name. + * + * @throws \Drupal\Core\TypedData\MissingDataException + * If the complex data structure is unset and no property can be created. */ public function toArray(); diff --git a/core/lib/Drupal/Core/TypedData/ListInterface.php b/core/lib/Drupal/Core/TypedData/ListInterface.php index 438dddd..67d6a16 100644 --- a/core/lib/Drupal/Core/TypedData/ListInterface.php +++ b/core/lib/Drupal/Core/TypedData/ListInterface.php @@ -54,12 +54,12 @@ public function onChange($delta); * @param int $index * Index of the item to return. * - * @throws \Drupal\Core\TypedData\MissingDataException - * If the complex data structure is unset and no item can be created. - * * @return \Drupal\Core\TypedData\TypedDataInterface * The item at the specified position in this list. An empty item is created * if it does not exist yet. + * + * @throws \Drupal\Core\TypedData\MissingDataException + * If the complex data structure is unset and no item can be created. */ public function get($index); @@ -71,22 +71,22 @@ public function get($index); * @param mixed * Item to be stored at the specified position. * - * @throws \Drupal\Core\TypedData\MissingDataException - * If the complex data structure is unset and no item can be set. - * * @return static * Returns the list. + * + * @throws \Drupal\Core\TypedData\MissingDataException + * If the complex data structure is unset and no item can be set. */ public function set($index, $item); /** * Returns the first item in this list. * - * @throws \Drupal\Core\TypedData\MissingDataException - * If the complex data structure is unset and no item can be created. - * * @return \Drupal\Core\TypedData\TypedDataInterface * The first item in this list. + * + * @throws \Drupal\Core\TypedData\MissingDataException + * If the complex data structure is unset and no item can be created. */ public function first(); diff --git a/core/lib/Drupal/Core/TypedData/TypedDataInterface.php b/core/lib/Drupal/Core/TypedData/TypedDataInterface.php index a54b9be..17bed01 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataInterface.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataInterface.php @@ -30,11 +30,11 @@ * (optional) The parent object of the data property, or NULL if it is the * root of a typed data tree. Defaults to NULL. * - * @see \Drupal\Core\TypedData\TypedDataManager::create() - * * @todo When \Drupal\Core\Config\TypedConfigManager has been fixed to use * class-based definitions, type-hint $definition to * DataDefinitionInterface. https://drupal.org/node/1928868 + * + * @see \Drupal\Core\TypedData\TypedDataManager::create() */ public static function createInstance($definition, $name = NULL, TypedDataInterface $parent = NULL); diff --git a/core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php b/core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php index 4673457..d5ba85a 100644 --- a/core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php +++ b/core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php @@ -73,10 +73,6 @@ public function normalize($field_item, $format = NULL, array $context = array()) // Normalize the target entity. $embedded = $this->serializer->normalize($target_entity, $format, $context); - // @todo Config entities currently can not be serialized, skip them. - if (empty($embedded['_links']['self'])) { - return array(); - } $link = $embedded['_links']['self']; // If the field is translatable, add the langcode to the link relation // object. This does not indicate the language of the target entity.