diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php index 11c4f0d..be31562 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php @@ -341,6 +341,9 @@ public function calculateDependencies() { parent::calculateDependencies(); // Ensure the field is dependent on the providing module. $this->addDependency('module', $this->module); + // Ensure the field is dependent on the provider of the entity type. + $entity_type = \Drupal::entityManager()->getDefinition($this->entity_type); + $this->addDependency('module', $entity_type->getProvider()); return $this->dependencies; } diff --git a/core/modules/field/tests/Drupal/field/Tests/FieldConfigEntityUnitTest.php b/core/modules/field/tests/Drupal/field/Tests/FieldConfigEntityUnitTest.php index 59f3359..0e1c723 100644 --- a/core/modules/field/tests/Drupal/field/Tests/FieldConfigEntityUnitTest.php +++ b/core/modules/field/tests/Drupal/field/Tests/FieldConfigEntityUnitTest.php @@ -62,36 +62,55 @@ public static function getInfo() { * {@inheritdoc} */ public function setUp() { - $this->entityTypeId = $this->randomName(); - - $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); - $this->entityType->expects($this->any()) - ->method('getProvider') - ->will($this->returnValue('entity')); - $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); - $this->entityManager->expects($this->any()) - ->method('getDefinition') - ->with($this->entityTypeId) - ->will($this->returnValue($this->entityType)); - $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('uuid', $this->uuid); \Drupal::setContainer($container); - } /** * @covers ::calculateDependencies */ public function testCalculateDependencies() { - $values = array('name' => 'test_field', 'type' => 'test_field_type', 'entity_type' => 'test_entity_type', 'module' => 'test_module'); - $entity = new FieldConfig($values, $this->entityTypeId); - $dependencies = $entity->calculateDependencies(); + // Create a mock entity type for fieldConfig. + $fieldConfigentityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $fieldConfigentityType->expects($this->any()) + ->method('getProvider') + ->will($this->returnValue('field')); + + // Create a mock entity type to attach the field to. + $attached_entity_type_id = $this->randomName(); + $attached_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $attached_entity_type->expects($this->any()) + ->method('getProvider') + ->will($this->returnValue('entity_provider_module')); + + // Get definition is called three times. Twice in + // ConfigEntityBase::addDependency() to get the provider of the field config + // entity type and once in FieldConfig::calculateDependencies() to get the + // provider of the entity type that field is attached to. + $this->entityManager->expects($this->at(0)) + ->method('getDefinition') + ->with('fieldConfig') + ->will($this->returnValue($fieldConfigentityType)); + $this->entityManager->expects($this->at(1)) + ->method('getDefinition') + ->with($attached_entity_type_id) + ->will($this->returnValue($attached_entity_type)); + $this->entityManager->expects($this->at(2)) + ->method('getDefinition') + ->with('fieldConfig') + ->will($this->returnValue($fieldConfigentityType)); + + $values = array('name' => 'test_field', 'type' => 'test_field_type', 'entity_type' => $attached_entity_type_id, 'module' => 'test_module'); + $field = new FieldConfig($values, 'fieldConfig'); + + $dependencies = $field->calculateDependencies(); $this->assertContains('test_module', $dependencies['module']); + $this->assertContains('entity_provider_module', $dependencies['module']); } } diff --git a/core/modules/field/tests/modules/field_test_config/config/field.field.entity_test.field_test_import.yml b/core/modules/field/tests/modules/field_test_config/config/field.field.entity_test.field_test_import.yml index 28036f9..32f1cc8 100644 --- a/core/modules/field/tests/modules/field_test_config/config/field.field.entity_test.field_test_import.yml +++ b/core/modules/field/tests/modules/field_test_config/config/field.field.entity_test.field_test_import.yml @@ -14,4 +14,5 @@ indexes: - format dependencies: module: + - entity_test - text diff --git a/core/modules/field/tests/modules/field_test_config/config/field.field.entity_test.field_test_import_2.yml b/core/modules/field/tests/modules/field_test_config/config/field.field.entity_test.field_test_import_2.yml index 4c2042b..cd4bf75 100644 --- a/core/modules/field/tests/modules/field_test_config/config/field.field.entity_test.field_test_import_2.yml +++ b/core/modules/field/tests/modules/field_test_config/config/field.field.entity_test.field_test_import_2.yml @@ -14,4 +14,5 @@ indexes: - format dependencies: module: + - entity_test - text diff --git a/core/modules/field/tests/modules/field_test_config/staging/field.field.entity_test.field_test_import_staging.yml b/core/modules/field/tests/modules/field_test_config/staging/field.field.entity_test.field_test_import_staging.yml index f4b6e1a..057c034 100644 --- a/core/modules/field/tests/modules/field_test_config/staging/field.field.entity_test.field_test_import_staging.yml +++ b/core/modules/field/tests/modules/field_test_config/staging/field.field.entity_test.field_test_import_staging.yml @@ -15,4 +15,5 @@ indexes: - format dependencies: module: + - entity_test - text diff --git a/core/modules/field/tests/modules/field_test_config/staging/field.field.entity_test.field_test_import_staging_2.yml b/core/modules/field/tests/modules/field_test_config/staging/field.field.entity_test.field_test_import_staging_2.yml index 8bb4272..d5d8964 100644 --- a/core/modules/field/tests/modules/field_test_config/staging/field.field.entity_test.field_test_import_staging_2.yml +++ b/core/modules/field/tests/modules/field_test_config/staging/field.field.entity_test.field_test_import_staging_2.yml @@ -15,4 +15,5 @@ indexes: - format dependencies: module: + - entity_test - text diff --git a/core/modules/forum/config/field.field.taxonomy_term.forum_container.yml b/core/modules/forum/config/field.field.taxonomy_term.forum_container.yml index af5ebf2..a666915 100644 --- a/core/modules/forum/config/field.field.taxonomy_term.forum_container.yml +++ b/core/modules/forum/config/field.field.taxonomy_term.forum_container.yml @@ -17,3 +17,4 @@ indexes: { } dependencies: module: - options + - taxonomy diff --git a/core/profiles/standard/config/field.field.node.field_image.yml b/core/profiles/standard/config/field.field.node.field_image.yml index de766b4..4b81618 100644 --- a/core/profiles/standard/config/field.field.node.field_image.yml +++ b/core/profiles/standard/config/field.field.node.field_image.yml @@ -21,4 +21,5 @@ status: true langcode: und dependencies: module: + - node - image diff --git a/core/profiles/standard/config/field.field.node.field_tags.yml b/core/profiles/standard/config/field.field.node.field_tags.yml index 7018e87..d4bd7c3 100644 --- a/core/profiles/standard/config/field.field.node.field_tags.yml +++ b/core/profiles/standard/config/field.field.node.field_tags.yml @@ -18,4 +18,5 @@ status: true langcode: und dependencies: module: + - node - taxonomy diff --git a/core/profiles/standard/config/field.field.user.user_picture.yml b/core/profiles/standard/config/field.field.user.user_picture.yml index 01890b1..986d7bf 100644 --- a/core/profiles/standard/config/field.field.user.user_picture.yml +++ b/core/profiles/standard/config/field.field.user.user_picture.yml @@ -22,3 +22,4 @@ indexes: dependencies: module: - image + - user