diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index da0bc47..376cfd8 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -340,7 +340,11 @@ protected function buildBaseFieldDefinitions($entity_type_id) { $base_field_definitions = $class::baseFieldDefinitions($entity_type); $provider = $entity_type->getProvider(); foreach ($base_field_definitions as $definition) { - $definition->setProvider($provider); + // @todo Remove this check one FieldDefinitionInterface exposes a proper + // provider setter. See https://drupal.org/node/2225961. + if ($definition instanceof FieldDefinition) { + $definition->setProvider($provider); + } } // Retrieve base field definitions from modules. @@ -350,7 +354,11 @@ protected function buildBaseFieldDefinitions($entity_type_id) { // Ensure the provider key actually matches the name of the provider // defining the field. foreach ($module_definitions as $field_name => $definition) { - $definition->setProvider($module); + // @todo Remove this check one FieldDefinitionInterface exposes a + // proper provider setter. See https://drupal.org/node/2225961. + if ($definition instanceof FieldDefinition) { + $definition->setProvider($module); + } $base_field_definitions[$field_name] = $definition; } } @@ -429,7 +437,11 @@ protected function buildBundleFieldDefinitions($entity_type_id, $bundle, array $ $provider = $entity_type->getProvider(); $bundle_field_definitions = $class::bundleFieldDefinitions($entity_type, $bundle, $base_field_definitions); foreach ($bundle_field_definitions as $definition) { - $definition->setProvider($provider); + // @todo Remove this check one FieldDefinitionInterface exposes a proper + // provider setter. See https://drupal.org/node/2225961. + if ($definition instanceof FieldDefinition) { + $definition->setProvider($provider); + } } // Retrieve base field definitions from modules. @@ -439,7 +451,11 @@ protected function buildBundleFieldDefinitions($entity_type_id, $bundle, array $ // Ensure the provider key actually matches the name of the provider // defining the field. foreach ($module_definitions as $field_name => $definition) { - $definition->setProvider($module); + // @todo Remove this check one FieldDefinitionInterface exposes a + // proper provider setter. See https://drupal.org/node/2225961. + if ($definition instanceof FieldDefinition) { + $definition->setProvider($module); + } $bundle_field_definitions[$field_name] = $definition; } } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index b58336f..5c82343 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -562,7 +562,10 @@ public function testGetFieldDefinitionsProvider() { $module = 'entity_manager_test_module'; - $field_definition = $this->getMockBuilder('Drupal\Core\Field\FieldDefinitionInterface') + // @todo Mock FieldDefinitionInterface once it exposes a proper provider + // setter. See https://drupal.org/node/2225961. + $field_definition = $this->getMockBuilder('Drupal\Core\Field\FieldDefinition') + ->disableOriginalConstructor() ->getMock(); // We expect two calls as the field definition will be returned from both