Commit 94bdf61b authored by catch's avatar catch

Issue #2232597 by alexpott: FieldConfig does not depend on the module the provides the entity type.

parent 6fe11acd
...@@ -341,6 +341,9 @@ public function calculateDependencies() { ...@@ -341,6 +341,9 @@ public function calculateDependencies() {
parent::calculateDependencies(); parent::calculateDependencies();
// Ensure the field is dependent on the providing module. // Ensure the field is dependent on the providing module.
$this->addDependency('module', $this->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; return $this->dependencies;
} }
......
...@@ -62,36 +62,55 @@ public static function getInfo() { ...@@ -62,36 +62,55 @@ public static function getInfo() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function setUp() { 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 = $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'); $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
$container = new ContainerBuilder(); $container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager); $container->set('entity.manager', $this->entityManager);
$container->set('uuid', $this->uuid); $container->set('uuid', $this->uuid);
\Drupal::setContainer($container); \Drupal::setContainer($container);
} }
/** /**
* @covers ::calculateDependencies * @covers ::calculateDependencies
*/ */
public function testCalculateDependencies() { public function testCalculateDependencies() {
$values = array('name' => 'test_field', 'type' => 'test_field_type', 'entity_type' => 'test_entity_type', 'module' => 'test_module'); // Create a mock entity type for fieldConfig.
$entity = new FieldConfig($values, $this->entityTypeId); $fieldConfigentityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
$dependencies = $entity->calculateDependencies(); $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('test_module', $dependencies['module']);
$this->assertContains('entity_provider_module', $dependencies['module']);
} }
} }
...@@ -14,4 +14,5 @@ indexes: ...@@ -14,4 +14,5 @@ indexes:
- format - format
dependencies: dependencies:
module: module:
- entity_test
- text - text
...@@ -14,4 +14,5 @@ indexes: ...@@ -14,4 +14,5 @@ indexes:
- format - format
dependencies: dependencies:
module: module:
- entity_test
- text - text
...@@ -15,4 +15,5 @@ indexes: ...@@ -15,4 +15,5 @@ indexes:
- format - format
dependencies: dependencies:
module: module:
- entity_test
- text - text
...@@ -15,4 +15,5 @@ indexes: ...@@ -15,4 +15,5 @@ indexes:
- format - format
dependencies: dependencies:
module: module:
- entity_test
- text - text
...@@ -17,3 +17,4 @@ indexes: { } ...@@ -17,3 +17,4 @@ indexes: { }
dependencies: dependencies:
module: module:
- options - options
- taxonomy
...@@ -21,4 +21,5 @@ status: true ...@@ -21,4 +21,5 @@ status: true
langcode: und langcode: und
dependencies: dependencies:
module: module:
- node
- image - image
...@@ -18,4 +18,5 @@ status: true ...@@ -18,4 +18,5 @@ status: true
langcode: und langcode: und
dependencies: dependencies:
module: module:
- node
- taxonomy - taxonomy
...@@ -22,3 +22,4 @@ indexes: ...@@ -22,3 +22,4 @@ indexes:
dependencies: dependencies:
module: module:
- image - image
- user
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment