diff -u b/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php b/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php --- b/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php +++ b/core/lib/Drupal/Core/Entity/TypedData/EntityDataDefinition.php @@ -21,10 +21,12 @@ public static function create($entity_type_id = NULL, $bundle = NULL) { // If the entity type is known, use the derived definition. if (isset($entity_type_id)) { + $data_type = "entity:{$entity_type_id}"; + // If a bundle was given, use the bundle-specific definition. - $data_type = isset($bundle) ? - sprintf('entity:%s:%s', $entity_type_id, $bundle) : - sprintf('entity:%s', $entity_type_id); + if ($bundle) { + $data_type .= ":{$bundle}"; + } // If the definition doesn't exist, just create from defaults. $values = \Drupal::typedDataManager()->getDefinition($data_type, FALSE); @@ -33,6 +35,11 @@ // Set the passed entity type. $definition->setEntityTypeId($entity_type_id); + // Set the passed bundle, if it was given. + if ($bundle) { + $definition->setBundles([$bundle]); + } + return $definition; } @@ -47,17 +54,10 @@ if ($parts[0] != 'entity') { throw new \InvalidArgumentException('Data type must be in the form of "entity:ENTITY_TYPE:BUNDLE."'); } - $entity_type_id = isset($parts[1]) ? $parts[1] : NULL; - $bundle = isset($parts[2]) ? $parts[2] : NULL; - $definition = static::create($entity_type_id, $bundle); - // Set the passed entity type and bundle. - if ($entity_type_id) { - $definition->setEntityTypeId($entity_type_id); - } - if ($bundle) { - $definition->setBundles([$bundle]); - } - return $definition; + return static::create( + isset($parts[1]) ? $parts[1] : NULL, + isset($parts[2]) ? $parts[2] : NULL + ); } /** diff -u b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php --- b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php +++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php @@ -94,7 +94,7 @@ $typed_data_manager->expects($this->any()) ->method('getDefinition') ->will($this->returnValueMap([ - 'entity:user' => $this->getMock('Drupal\Core\TypedData\DataDefinitionInterface'), + 'entity:user' => ['class' => '\Drupal\Core\TypedData\DataDefinitionInterface'], 'field_item:string_long' => ['class' => '\Drupal\Core\Field\Plugin\Field\FieldType\StringLongItem'], ])); diff -u b/core/tests/Drupal/KernelTests/Core/Entity/EntityTypedDataDefinitionTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityTypedDataDefinitionTest.php --- b/core/tests/Drupal/KernelTests/Core/Entity/EntityTypedDataDefinitionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityTypedDataDefinitionTest.php @@ -95,8 +95,8 @@ $this->assertTrue($entity_definition instanceof ComplexDataDefinitionInterface); // Entity definitions should inherit their labels from the entity type. - $this->assertEqual($entity_definition->getLabel(), \Drupal::entityTypeManager()->getDefinition('node')->getLabel()); - $this->assertEqual($bundle_definition->getLabel(), \Drupal::service('entity_type.bundle.info')->getBundleInfo('node')['article']['label']); + $this->assertEquals('Content', $entity_definition->getLabel()); + $this->assertEquals('Article', $bundle_definition->getLabel()); $field_definitions = $entity_definition->getPropertyDefinitions(); // Comparison should ignore the internal static cache, so compare the