diff --git a/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php b/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php index 0ed2eef..222949d 100644 --- a/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php +++ b/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php @@ -112,8 +112,17 @@ public function getBundles() { /** * {@inheritdoc} */ - public function setBundles(array $bundles) { - return $this->addConstraint('Bundle', $bundles); + public function setBundles(array $bundles = NULL) { + if (isset($bundles)) { + $this->addConstraint('Bundle', $bundles); + } + else { + // Remove the constraint. + $constraints = $this->getConstraints(); + unset($constraints['Bundle']); + $this->setConstraints($constraints); + } + return $this; } } diff --git a/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinitionInterface.php b/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinitionInterface.php index 9b57384..933d3a3 100644 --- a/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinitionInterface.php +++ b/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinitionInterface.php @@ -37,19 +37,18 @@ public function setEntityTypeId($entity_type_id); * Returns the array of possible entity bundles. * * @return array|null - * The array of possible bundles, or NULL if the bundle is unknown or the - * entity type does not have bundles. + * The array of possible bundles, or NULL for any. */ public function getBundles(); /** * Sets the array of possible entity bundles. * - * @param array $bundles - * The bundles to set. + * @param array|null $bundles + * The array of possible bundles, or NULL for any. * * @return static * The object itself for chaining. */ - public function setBundles(array $bundles); + public function setBundles(array $bundles = NULL); } diff --git a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php index 39fdc83..c182231 100644 --- a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php +++ b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php @@ -103,22 +103,6 @@ public function getSettings(); public function getSetting($setting_name); /** - * Returns the names of the field's subproperties. - * - * A field is a list of items, and each item can contain one or more - * properties. All items for a given field contain the same property names, - * but the values can be different for each item. - * - * For example, an email field might just contain a single 'value' property, - * while a link field might contain 'title' and 'url' properties, and a text - * field might contain 'value', 'summary', and 'format' properties. - * - * @return array - * The property names. - */ - public function getPropertyNames(); - - /** * Returns whether the field is translatable. * * @return bool @@ -276,6 +260,22 @@ public function getPropertyDefinition($name); public function getPropertyDefinitions(); /** + * Returns the names of the field's subproperties. + * + * A field is a list of items, and each item can contain one or more + * properties. All items for a given field contain the same property names, + * but the values can be different for each item. + * + * For example, an email field might just contain a single 'value' property, + * while a link field might contain 'title' and 'url' properties, and a text + * field might contain 'value', 'summary', and 'format' properties. + * + * @return array + * The property names. + */ + public function getPropertyNames(); + + /** * Returns the name of the main property, if any. * * Some field items consist mainly of one main property, e.g. the value of a diff --git a/core/lib/Drupal/Core/Field/FieldItemBase.php b/core/lib/Drupal/Core/Field/FieldItemBase.php index 8efa994..403dc25 100644 --- a/core/lib/Drupal/Core/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Field/FieldItemBase.php @@ -26,7 +26,7 @@ /** * {@inheritdoc} */ - public static function getMainPropertyName() { + public static function mainPropertyName() { return 'value'; } @@ -37,7 +37,7 @@ public function __construct(DataDefinitionInterface $definition, $name = NULL, T parent::__construct($definition, $name, $parent); // Initialize computed properties by default, such that they get cloned // with the whole item. - foreach ($this->getPropertyDefinitions() as $name => $definition) { + foreach ($this->definition->getPropertyDefinitions() as $name => $definition) { if ($definition->isComputed()) { $this->properties[$name] = \Drupal::typedDataManager()->getPropertyInstance($this, $name); } @@ -98,7 +98,7 @@ public function setValue($values, $notify = TRUE) { // Treat the values as property value of the first property, if no array is // given. if (isset($values) && !is_array($values)) { - $keys = array_keys($this->getPropertyDefinitions()); + $keys = array_keys($this->definition->getPropertyDefinitions()); $values = array($keys[0] => $values); } $this->values = $values; diff --git a/core/lib/Drupal/Core/Field/FieldItemInterface.php b/core/lib/Drupal/Core/Field/FieldItemInterface.php index b6a9653..899fbad 100644 --- a/core/lib/Drupal/Core/Field/FieldItemInterface.php +++ b/core/lib/Drupal/Core/Field/FieldItemInterface.php @@ -46,7 +46,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin * * @see \Drupal\Core\Field\FieldDefinition */ - public static function getMainPropertyName(); + public static function mainPropertyName(); /** * Returns the schema for the field. diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php index ce449af..f83c427 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -71,7 +71,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin /** * {@inheritdoc} */ - public static function getMainPropertyName() { + public static function mainPropertyName() { return 'target_id'; } diff --git a/core/lib/Drupal/Core/TypedData/ComplexDataDefinitionBase.php b/core/lib/Drupal/Core/TypedData/ComplexDataDefinitionBase.php index ac70ef5..1fa5dab 100644 --- a/core/lib/Drupal/Core/TypedData/ComplexDataDefinitionBase.php +++ b/core/lib/Drupal/Core/TypedData/ComplexDataDefinitionBase.php @@ -16,14 +16,17 @@ * An array of data definitions. * * @var \Drupal\Core\TypedData\DataDefinitionInterface[] - * - * @see ComplexDataDefinitionBase::getPropertyDefinitions() */ protected $propertyDefinitions; /** * {@inheritdoc} */ + abstract public function getPropertyDefinitions(); + + /** + * {@inheritdoc} + */ public function getPropertyDefinition($name) { if (!isset($this->propertyDefinitions)) { $this->getPropertyDefinitions(); @@ -36,16 +39,6 @@ public function getPropertyDefinition($name) { /** * {@inheritdoc} */ - public function __sleep() { - // Do not serialize the cached property definitions. - $vars = get_object_vars($this); - unset($vars['propertyDefinitions']); - return array_keys($vars); - } - - /** - * {@inheritdoc} - */ public function getMainPropertyName() { return NULL; } @@ -53,6 +46,11 @@ public function getMainPropertyName() { /** * {@inheritdoc} */ - abstract public function getPropertyDefinitions(); + public function __sleep() { + // Do not serialize the cached property definitions. + $vars = get_object_vars($this); + unset($vars['propertyDefinitions']); + return array_keys($vars); + } } diff --git a/core/lib/Drupal/Core/TypedData/DataDefinition.php b/core/lib/Drupal/Core/TypedData/DataDefinition.php index dd1d400..a902ef0 100644 --- a/core/lib/Drupal/Core/TypedData/DataDefinition.php +++ b/core/lib/Drupal/Core/TypedData/DataDefinition.php @@ -43,11 +43,11 @@ public static function createFromDataType($type) { /** * Constructs a new data definition object. * - * @param array $definition - * (optional) If given, a data definition represented as array. + * @param array $values + * (optional) If given, an array of initial values to set on the definition. */ - public function __construct(array $definition = array()) { - $this->definition = $definition; + public function __construct(array $values = array()) { + $this->definition = $values; } /** diff --git a/core/lib/Drupal/Core/TypedData/ListDataDefinition.php b/core/lib/Drupal/Core/TypedData/ListDataDefinition.php index 412803e..75e93e8 100644 --- a/core/lib/Drupal/Core/TypedData/ListDataDefinition.php +++ b/core/lib/Drupal/Core/TypedData/ListDataDefinition.php @@ -52,8 +52,8 @@ public static function createFromItemType($item_type) { /** * {@inheritdoc} */ - public function __construct(array $definition = array(), DataDefinitionInterface $item_definition = NULL) { - $this->definition = $definition; + public function __construct(array $values = array(), DataDefinitionInterface $item_definition = NULL) { + $this->definition = $values; $this->itemDefinition = $item_definition; } diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php index 30ac403..d895632 100644 --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php @@ -7,7 +7,6 @@ namespace Drupal\Core\TypedData\Plugin\DataType; -use Drupal\Core\TypedData\MapDataDefinition; use Drupal\Core\TypedData\TypedData; use Drupal\Core\TypedData\ComplexDataInterface; @@ -154,7 +153,7 @@ public function set($property_name, $value, $notify = TRUE) { */ public function getProperties($include_computed = FALSE) { $properties = array(); - foreach ($this->getPropertyDefinitions() as $name => $definition) { + foreach ($this->definition->getPropertyDefinitions() as $name => $definition) { if ($include_computed || !$definition->isComputed()) { $properties[$name] = $this->get($name); } diff --git a/core/modules/config_translation/tests/Drupal/config_translation/Tests/ConfigMapperManagerTest.php b/core/modules/config_translation/tests/Drupal/config_translation/Tests/ConfigMapperManagerTest.php index 5f4afe5..860941b 100644 --- a/core/modules/config_translation/tests/Drupal/config_translation/Tests/ConfigMapperManagerTest.php +++ b/core/modules/config_translation/tests/Drupal/config_translation/Tests/ConfigMapperManagerTest.php @@ -164,7 +164,7 @@ public function providerTestHasTranslatable() { protected function getElement(array $definition) { $element = $this->getMock('Drupal\Core\TypedData\TypedDataInterface'); $element->expects($this->any()) - ->method('getDefinition') + ->method('getDataDefinition') ->will($this->returnValue($definition)); return $element; } diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index fde8db0..3841820 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -628,14 +628,14 @@ function _editor_get_file_uuids_by_field(EntityInterface $entity) { * The names of the fields on this entity that have text processing enabled. */ function _editor_get_processed_text_fields(ContentEntityInterface $entity) { - $fields = $entity->getFieldDefinitions(); - if (empty($fields)) { + $field_definitions = $entity->getFieldDefinitions(); + if (empty($field_definitions)) { return array(); } // Find all configurable fields, because only they could have a // text_processing setting. - $configurable_fields = array_keys(array_filter($fields, function ($definition) { + $configurable_fields = array_keys(array_filter($field_definitions, function ($definition) { return $definition->isConfigurable(); })); if (empty($configurable_fields)) { diff --git a/core/modules/field/lib/Drupal/field/Entity/Field.php b/core/modules/field/lib/Drupal/field/Entity/Field.php index aceb2f7..96ba183 100644 --- a/core/modules/field/lib/Drupal/field/Entity/Field.php +++ b/core/modules/field/lib/Drupal/field/Entity/Field.php @@ -453,8 +453,7 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont public function getSchema() { if (!isset($this->schema)) { // Get the schema from the field item class. - $definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($this->type); - $class = $definition['class']; + $class = $this->getFieldItemClass(); $schema = $class::schema($this); // Fill in default values for optional entries. $schema += array('indexes' => array(), 'foreign keys' => array()); 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 65fb4ab..eece832 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -7,8 +7,6 @@ namespace Drupal\system\Tests\Entity; -use Drupal\Core\Entity\TypedData\EntityDataDefinition; -use Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\FieldDefinition; use Drupal\Core\Field\FieldDefinitionInterface; diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTypedDataDefinitionTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTypedDataDefinitionTest.php index 7fae753..3e0fe10 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTypedDataDefinitionTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTypedDataDefinitionTest.php @@ -67,8 +67,7 @@ public function testFields() { $this->assertEqual($field_item_definition->getMainPropertyName(), 'value'); $this->assertNull($field_item_definition->getPropertyDefinition('invalid')); - // To ease access of field item property metadata, field definitions make - // metadata about field item properties on the field level as well. + // Test accessing field item property metadata via the field definition. $this->assertTrue($field_definition instanceof FieldDefinitionInterface); $this->assertEqual(array_keys($field_definition->getPropertyDefinitions()), array('value')); $this->assertEqual($field_definition->getPropertyDefinition('value')->getDataType(), 'integer'); @@ -76,12 +75,12 @@ public function testFields() { $this->assertNull($field_definition->getPropertyDefinition('invalid')); // Test using the definition factory for field item lists and field items. - $field_item2 = $this->typedDataManager->createDataDefinition('field_item:integer'); - $this->assertFalse($field_item2 instanceof ListDataDefinitionInterface); - $this->assertTrue($field_item2 instanceof ComplexDataDefinitionInterface); + $field_item = $this->typedDataManager->createDataDefinition('field_item:integer'); + $this->assertFalse($field_item instanceof ListDataDefinitionInterface); + $this->assertTrue($field_item instanceof ComplexDataDefinitionInterface); // Comparison should ignore the internal static cache, so compare the // serialized objects instead. - $this->assertEqual(serialize($field_item_definition), serialize($field_item2)); + $this->assertEqual(serialize($field_item_definition), serialize($field_item)); $field_definition2 = $this->typedDataManager->createListDataDefinition('field_item:integer'); $this->assertTrue($field_definition2 instanceof ListDataDefinitionInterface); @@ -111,7 +110,7 @@ public function testEntities() { $this->assertTrue($entity_definition2 instanceof ComplexDataDefinitionInterface); $this->assertEqual(serialize($entity_definition), serialize($entity_definition2)); - // Test that definition factory creates the right definitions for all + // Test that the definition factory creates the right definitions for all // entity data types variants. $this->assertEqual($this->typedDataManager->createDataDefinition('entity'), EntityDataDefinition::create()); $this->assertEqual($this->typedDataManager->createDataDefinition('entity:node'), EntityDataDefinition::create('node')); @@ -128,7 +127,7 @@ public function testEntityReferences() { $this->assertEqual($reference_definition->getTargetDefinition()->getDataType(), 'entity'); $this->assertTrue($reference_definition->getTargetDefinition() instanceof \Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface); - // Test using the definition factory. + // Test that the definition factory creates the right definition object. $reference_definition2 = $this->typedDataManager->createDataDefinition('entity_reference'); $this->assertTrue($reference_definition2 instanceof DataReferenceDefinitionInterface); $this->assertEqual($reference_definition2, $reference_definition); diff --git a/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataDefinitionTest.php b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataDefinitionTest.php index 57a7bd6..aa9d3c1 100644 --- a/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataDefinitionTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataDefinitionTest.php @@ -57,8 +57,8 @@ public function testLists() { $this->assertTrue($list_definition2 instanceof ListDataDefinitionInterface); $this->assertEqual($list_definition, $list_definition2); - // Test creating a single list item, which is the same as a list of any - // items. + // Test creating the definition of data with type 'list', which is the same + // as creating a definition of a list of items of type 'any'. $list_definition = $this->typedDataManager->createDataDefinition('list'); $this->assertTrue($list_definition instanceof ListDataDefinitionInterface); $this->assertEqual($list_definition->getDataType(), 'list'); diff --git a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php index 340e98b..9cac637 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php +++ b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php @@ -66,7 +66,7 @@ public function getCacheData() { // the sanitized value in the filter cache separately. $text_processing = $this->getSetting('text_processing'); if (!$text_processing || filter_format_allowcache($this->get('format')->getValue())) { - foreach ($this->getPropertyDefinitions() as $property => $definition) { + foreach ($this->definition->getPropertyDefinitions() as $property => $definition) { if ($definition->getClass() == '\Drupal\text\TextProcessed') { $data[$property] = $this->get($property)->getValue(); } @@ -85,7 +85,7 @@ public function onChange($property_name) { } // Unset processed properties that are affected by the change. - foreach ($this->getPropertyDefinitions() as $property => $definition) { + foreach ($this->definition->getPropertyDefinitions() as $property => $definition) { if ($definition->getClass() == '\Drupal\text\TextProcessed') { if ($property_name == 'format' || ($definition->getSetting('text source') == $property_name)) { $this->set($property, NULL, FALSE);