Issue #2224209 by alexpott: Field instance configuration should depend on its bundle.

8.0.x
catch 2014-03-25 13:38:24 +00:00
parent 13242b5af6
commit 34907c36cc
11 changed files with 105 additions and 53 deletions

View File

@ -51,6 +51,13 @@ class CommentValidationTest extends EntityUnitTestBase {
'name' => 'comment',
'type' => 'comment',
))->save();
// Create a page node type.
$this->entityManager->getStorageController('node_type')->create(array(
'type' => 'page',
'name' => 'page',
))->save();
// Add comment field instance to page content.
$this->entityManager->getStorageController('field_instance_config')->create(array(
'field_name' => 'comment',

View File

@ -47,6 +47,11 @@ class ContactFieldsTest extends ViewTestBase {
));
$this->field->save();
entity_create('contact_category', array(
'id' => 'contact_message',
'label' => 'Test contact category',
))->save();
entity_create('field_instance_config', array(
'field_name' => $this->field->name,
'entity_type' => 'contact_message',

View File

@ -368,6 +368,13 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
parent::calculateDependencies();
// Manage dependencies.
$this->addDependency('entity', $this->field->getConfigDependencyName());
$bundle_entity_type_id = \Drupal::entityManager()->getDefinition($this->entity_type)->getBundleEntityType();
if ($bundle_entity_type_id != 'bundle') {
// If the target entity type uses entities to manage its bundles then
// depend on the bundle entity.
$bundle_entity = \Drupal::entityManager()->getStorageController($bundle_entity_type_id)->load($this->bundle);
$this->addDependency('entity', $bundle_entity->getConfigDependencyName());
}
return $this->dependencies;
}

View File

@ -52,6 +52,12 @@ abstract class FieldTestBase extends ViewTestBase {
protected function setUp() {
parent::setUp();
// Ensure the page node type exists.
entity_create('node_type', array(
'type' => 'page',
'name' => 'page',
))->save();
ViewTestData::createTestViews(get_class($this), array('field_test_views'));
}

View File

@ -71,16 +71,7 @@ class FieldInstanceConfigEntityUnitTest extends UnitTestCase {
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');
@ -111,10 +102,40 @@ class FieldInstanceConfigEntityUnitTest extends UnitTestCase {
->method('getField')
->with('test_entity_type', 'test_field')
->will($this->returnValue($field));
$values = array('field_name' => 'test_field', 'entity_type' => 'test_entity_type', $this->entityTypeId, 'bundle' => 'test_bundle');
// Mock the interfaces necessary to create a dependency on a bundle entity.
$bundle_entity = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityInterface');
$bundle_entity->expects($this->any())
->method('getConfigDependencyName')
->will($this->returnValue('test.test_entity_type.id'));
$storage_controller = $this->getMock('\Drupal\Core\Config\Entity\ConfigStorageControllerInterface');
$storage_controller
->expects($this->any())
->method('load')
->with('test_bundle')
->will($this->returnValue($bundle_entity));
$this->entityManager->expects($this->any())
->method('getStorageController')
->with('bundle_entity_type')
->will($this->returnValue($storage_controller));
$target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
$target_entity_type->expects($this->any())
->method('getBundleEntityType')
->will($this->returnValue('bundle_entity_type'));
$this->entityManager->expects($this->any())
->method('getDefinition')
->with('test_entity_type')
->will($this->returnValue($target_entity_type));
$values = array('field_name' => 'test_field', 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle');
$entity = new FieldInstanceConfig($values, $this->entityTypeId);
$dependencies = $entity->calculateDependencies();
$this->assertContains('field.field.test_entity_type.test_field', $dependencies['entity']);
$this->assertContains('test.test_entity_type.id', $dependencies['entity']);
}
}

View File

@ -16,3 +16,4 @@ field_type: list_boolean
dependencies:
entity:
- field.field.forum.forum_container
- taxonomy.vocabulary.forums

View File

@ -53,6 +53,29 @@ class NodeAccessLanguageAwareCombinationTest extends NodeTestBase {
public function setUp() {
parent::setUp();
// Create the 'private' field, which allows the node to be marked as private
// (restricted access) in a given translation.
$field_private = entity_create('field_config', array(
'name' => 'field_private',
'entity_type' => 'node',
'type' => 'list_boolean',
'cardinality' => 1,
'translatable' => TRUE,
'settings' => array(
'allowed_values' => array(0 => 'Not private', 1 => 'Private'),
),
));
$field_private->save();
entity_create('field_instance_config', array(
'field_name' => $field_private->name,
'entity_type' => 'node',
'bundle' => 'page',
'widget' => array(
'type' => 'options_buttons',
),
))->save();
// After enabling a node access module, the access table has to be rebuild.
node_access_rebuild();

View File

@ -46,6 +46,29 @@ class NodeAccessLanguageAwareTest extends NodeTestBase {
public function setUp() {
parent::setUp();
// Create the 'private' field, which allows the node to be marked as private
// (restricted access) in a given translation.
$field_private = entity_create('field_config', array(
'name' => 'field_private',
'entity_type' => 'node',
'type' => 'list_boolean',
'cardinality' => 1,
'translatable' => TRUE,
'settings' => array(
'allowed_values' => array(0 => 'Not private', 1 => 'Private'),
),
));
$field_private->save();
entity_create('field_instance_config', array(
'field_name' => $field_private->name,
'entity_type' => 'node',
'bundle' => 'page',
'widget' => array(
'type' => 'options_buttons',
),
))->save();
// After enabling a node access module, the access table has to be rebuild.
node_access_rebuild();

View File

@ -1,43 +0,0 @@
<?php
/**
* @file
* Install, update and uninstall functions for the node_access_test_language
* module.
*/
/**
* Implements hook_install().
*
* Creates the 'private' field, which allows the node to be marked as private
* (restricted access) in a given translation.
*/
function node_access_test_language_install() {
$field_private = entity_create('field_config', array(
'name' => 'field_private',
'entity_type' => 'node',
'type' => 'list_boolean',
'cardinality' => 1,
'translatable' => TRUE,
'settings' => array(
'allowed_values' => array(0 => 'Not private', 1 => 'Private'),
),
));
$field_private->save();
entity_create('field_instance_config', array(
'field_name' => $field_private->name,
'entity_type' => 'node',
'bundle' => 'page',
'widget' => array(
'type' => 'options_buttons',
),
))->save();
}
/**
* Implements hook_uninstall().
*/
function node_access_test_language_uninstall() {
entity_load('field_instance_config', 'node.page.field_private')->delete();
}

View File

@ -29,3 +29,4 @@ field_type: image
dependencies:
entity:
- field.field.node.field_image
- node.type.article

View File

@ -13,3 +13,4 @@ langcode: und
dependencies:
entity:
- field.field.node.field_tags
- node.type.article