commit b51348d7b3134e0902aef3ab95ad97ddae5d4188 Author: fago Date: Sun Dec 16 14:41:00 2012 +0100 Removed typed data namespaces and depend on the root data's type instead. diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 33f5caa..490470d 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -141,43 +141,39 @@ public function getOriginalEntity() { return $this; } - /** + /** * Implements \Drupal\Core\TypedData\ContextAwareInterface::getName(). */ public function getName() { - // @todo: Replace by EntityNG implementation once all entity types have been - // converted to use the entity field API. + return NULL; } /** - * Implements \Drupal\Core\TypedData\ContextAwareInterface::getNamespace(). + * Implements \Drupal\Core\TypedData\ContextAwareInterface::getRoot(). */ - public function getNamespace() { - // @todo: Replace by EntityNG implementation once all entity types have been - // converted to use the entity field API. + public function getRoot() { + return $this; } /** * Implements \Drupal\Core\TypedData\ContextAwareInterface::getPropertyPath(). */ public function getPropertyPath() { - // @todo: Replace by EntityNG implementation once all entity types have been - // converted to use the entity field API. + return ''; } /** * Implements \Drupal\Core\TypedData\ContextAwareInterface::getParent(). */ public function getParent() { - // @todo: Replace by EntityNG implementation once all entity types have been - // converted to use the entity field API. + return NULL; } /** * Implements \Drupal\Core\TypedData\ContextAwareInterface::setContext(). */ public function setContext($name = NULL, ContextAwareInterface $parent = NULL) { - // @todo: Replace by EntityNG implementation once all entity types have been - // converted to use the entity field API. + // As entities are always the root of the tree, we do not need to set any + // context. } } diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 3469ee0..adbb047 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -398,39 +398,35 @@ public function getOriginalEntity() { * Implements \Drupal\Core\TypedData\ContextAwareInterface::getName(). */ public function getName() { - // @todo: Replace by EntityNG implementation once all entity types have been - // converted to use the entity field API. + return NULL; } /** - * Implements \Drupal\Core\TypedData\ContextAwareInterface::getNamespace(). + * Implements \Drupal\Core\TypedData\ContextAwareInterface::getRoot(). */ - public function getNamespace() { - // @todo: Replace by EntityNG implementation once all entity types have been - // converted to use the entity field API. + public function getRoot() { + return $this; } /** * Implements \Drupal\Core\TypedData\ContextAwareInterface::getPropertyPath(). */ public function getPropertyPath() { - // @todo: Replace by EntityNG implementation once all entity types have been - // converted to use the entity field API. + return ''; } /** * Implements \Drupal\Core\TypedData\ContextAwareInterface::getParent(). */ public function getParent() { - // @todo: Replace by EntityNG implementation once all entity types have been - // converted to use the entity field API. + return NULL; } /** * Implements \Drupal\Core\TypedData\ContextAwareInterface::setContext(). */ public function setContext($name = NULL, ContextAwareInterface $parent = NULL) { - // @todo: Replace by EntityNG implementation once all entity types have been - // converted to use the entity field API. + // As entities are always the root of the tree, we do not need to set any + // context. } } diff --git a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php index cd663f4..2005bc0 100644 --- a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php +++ b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php @@ -330,8 +330,8 @@ public function getName() { /** * Forwards the call to the decorated entity. */ - public function getNamespace() { - return $this->decorated->getNamespace(); + public function getRoot() { + return $this->decorated->getRoot(); } /** diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index 38fd80a..5aee3bc 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -85,6 +85,15 @@ public function __construct(array $values, $entity_type, $bundle = FALSE) { } /** + * Gets the typed data type of the entity. + * + * @return string + */ + public function getType() { + return $this->entityType; + } + + /** * Initialize the object. Invoked upon construction and wake up. */ protected function init() { @@ -493,25 +502,4 @@ public function label($langcode = NULL) { } return $label; } - - /** - * Implements ContextAwareInterface::getName(). - */ - public function getName() { - return NULL; - } - - /** - * Implements ContextAwareInterface::getNamespace(). - */ - public function getNamespace() { - return 'Drupal.core.entity.' . $this->entityType; - } - - /** - * Implements ContextAwareInterface::getPropertyPath(). - */ - public function getPropertyPath() { - return ''; - } } diff --git a/core/lib/Drupal/Core/TypedData/ContextAwareInterface.php b/core/lib/Drupal/Core/TypedData/ContextAwareInterface.php index 143a9ef..9c9e55e 100644 --- a/core/lib/Drupal/Core/TypedData/ContextAwareInterface.php +++ b/core/lib/Drupal/Core/TypedData/ContextAwareInterface.php @@ -32,16 +32,15 @@ public function getName(); public function getParent(); /** - * Returns the typed data namespace of the typed data tree. + * Returns the root of the typed data tree. * - * A namespace to identify the current typed data tree, e.g. for the the tree - * of typed data objects of an entity it could be - * Drupal.core.entity.entity_type. + * Returns the root data for a tree of typed data objects; e.g. for an entity + * field item the root of the tree is its parent entity object. * - * @return string - * The namespace of the typed data tree, or NULL if it is not specified. + * @return \Drupal\Core\TypedData\ComplexDataInterface|\Drupal\Core\TypedData\ListInterface + * The root data structure, either complex data or a list. */ - public function getNamespace(); + public function getRoot(); /** * Returns the property path of the data. diff --git a/core/lib/Drupal/Core/TypedData/ContextAwareTypedData.php b/core/lib/Drupal/Core/TypedData/ContextAwareTypedData.php index 80a1df1..e713324 100644 --- a/core/lib/Drupal/Core/TypedData/ContextAwareTypedData.php +++ b/core/lib/Drupal/Core/TypedData/ContextAwareTypedData.php @@ -68,12 +68,13 @@ public function getName() { } /** - * Implements ContextAwareInterface::getNamespace(). + * Implements ContextAwareInterface::getRoot(). */ - public function getNamespace() { + public function getRoot() { if (isset($this->parent)) { - return $this->parent->getNamespace(); + return $this->parent->getRoot(); } + return $this; } /** diff --git a/core/lib/Drupal/Core/TypedData/TypedDataManager.php b/core/lib/Drupal/Core/TypedData/TypedDataManager.php index 3e747cf..c4ac55c 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -142,13 +142,15 @@ public function getInstance(array $options) { /** * Get a typed data instance for a property of a given typed data object. * - * If the object has a namespace and property path specified, this method - * will use prototyping for fast and efficient instantiation of many property - * objects with the same namespace and property path; e.g., if - * comment.comment_body.0.value is instantiated very often when multiple - * comments are used. + * This method will use prototyping for fast and efficient instantiation of + * many property objects with the same property path; e.g., + * when multiple comments are used comment_body.0.value needs to be + * instantiated very often. + * Prototyping is done by the root object's data type and the given + * property path, i.e. all property instances having the same property path + * and inheriting from the same data type are prototyped. * - * @param ContextAwareInterface $object + * @param \Drupal\Core\TypedData\ContextAwareInterface $object * The parent typed data object, implementing the ContextAwareInterface and * either the ListInterface or the ComplexDataInterface. * @param string $property_name @@ -167,15 +169,14 @@ public function getInstance(array $options) { * @see \Drupal\Core\TypedData\TypedDataManager::create() */ public function getPropertyInstance(ContextAwareInterface $object, $property_name, $value = NULL) { - $namespace = $object->getNamespace(); - $key = $namespace . ':' . $object->getPropertyPath() . '.'; + $key = $object->getRoot()->getType() . ':' . $object->getPropertyPath() . '.'; // If we are creating list items, we always use 0 in the key as all list // items look the same. $key .= is_numeric($property_name) ? 0 : $property_name; - // If a namespace is given, make sure we have a prototype. Then, clone the - // prototype and set object specific values, i.e. the value and the context. - if (!$namespace || !isset($this->prototypes[$key])) { + // Make sure we have a prototype. Then, clone the prototype and set object + // specific values, i.e. the value and the context. + if (!isset($this->prototypes[$key])) { if ($object instanceof ComplexDataInterface) { $definition = $object->getPropertyDefinition($property_name); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php index 6f27146..07f4e03 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -317,25 +317,25 @@ public function testIntrospection() { // them from the $userref_values['entity'] property. // Make sure provided contextual information is right. - $this->assertEqual($entity->getNamespace(), 'Drupal.core.entity.entity_test'); + $this->assertIdentical($entity->getRoot(), $entity, 'Entity is root object.'); $this->assertEqual($entity->getPropertyPath(), ''); $this->assertEqual($entity->getName(), ''); $this->assertEqual($entity->getParent(), NULL); $field = $entity->user_id; - $this->assertEqual($field->getNamespace(), 'Drupal.core.entity.entity_test'); + $this->assertIdentical($field->getRoot(), $entity, 'Entity is root object.'); $this->assertEqual($field->getPropertyPath(), 'user_id'); $this->assertEqual($field->getName(), 'user_id'); $this->assertIdentical($field->getParent(), $entity, 'Parent object matches.'); $field_item = $field[0]; - $this->assertEqual($field_item->getNamespace(), 'Drupal.core.entity.entity_test'); + $this->assertIdentical($field_item->getRoot(), $entity, 'Entity is root object.'); $this->assertEqual($field_item->getPropertyPath(), 'user_id.0'); $this->assertEqual($field_item->getName(), '0'); $this->assertIdentical($field_item->getParent(), $field, 'Parent object matches.'); $item_value = $field_item->get('entity'); - $this->assertEqual($item_value->getNamespace(), 'Drupal.core.entity.entity_test'); + $this->assertIdentical($item_value->getRoot(), $entity, 'Entity is root object.'); $this->assertEqual($item_value->getPropertyPath(), 'user_id.0.entity'); $this->assertEqual($item_value->getName(), 'entity'); $this->assertIdentical($item_value->getParent(), $field_item, 'Parent object matches.'); diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php index 374fb38..db6c900 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -1103,9 +1103,9 @@ public function getName() { } /** - * Implements \Drupal\Core\TypedData\ContextAwareInterface::getNamespace(). + * Implements \Drupal\Core\TypedData\ContextAwareInterface::getRoot(). */ - public function getNamespace() { + public function getRoot() { return $this->__call(__FUNCTION__, func_get_args()); }