Commit 34907c36 authored by catch's avatar catch

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

parent 13242b5a
...@@ -51,6 +51,13 @@ public function testValidation() { ...@@ -51,6 +51,13 @@ public function testValidation() {
'name' => 'comment', 'name' => 'comment',
'type' => 'comment', 'type' => 'comment',
))->save(); ))->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. // Add comment field instance to page content.
$this->entityManager->getStorageController('field_instance_config')->create(array( $this->entityManager->getStorageController('field_instance_config')->create(array(
'field_name' => 'comment', 'field_name' => 'comment',
......
...@@ -47,6 +47,11 @@ protected function setUp() { ...@@ -47,6 +47,11 @@ protected function setUp() {
)); ));
$this->field->save(); $this->field->save();
entity_create('contact_category', array(
'id' => 'contact_message',
'label' => 'Test contact category',
))->save();
entity_create('field_instance_config', array( entity_create('field_instance_config', array(
'field_name' => $this->field->name, 'field_name' => $this->field->name,
'entity_type' => 'contact_message', 'entity_type' => 'contact_message',
......
...@@ -368,6 +368,13 @@ public function calculateDependencies() { ...@@ -368,6 +368,13 @@ public function calculateDependencies() {
parent::calculateDependencies(); parent::calculateDependencies();
// Manage dependencies. // Manage dependencies.
$this->addDependency('entity', $this->field->getConfigDependencyName()); $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; return $this->dependencies;
} }
......
...@@ -52,6 +52,12 @@ abstract class FieldTestBase extends ViewTestBase { ...@@ -52,6 +52,12 @@ abstract class FieldTestBase extends ViewTestBase {
protected function setUp() { protected function setUp() {
parent::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')); ViewTestData::createTestViews(get_class($this), array('field_test_views'));
} }
......
...@@ -71,16 +71,7 @@ public static function getInfo() { ...@@ -71,16 +71,7 @@ public static function getInfo() {
public function setUp() { public function setUp() {
$this->entityTypeId = $this->randomName(); $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');
...@@ -111,10 +102,40 @@ public function testCalculateDependencies() { ...@@ -111,10 +102,40 @@ public function testCalculateDependencies() {
->method('getField') ->method('getField')
->with('test_entity_type', 'test_field') ->with('test_entity_type', 'test_field')
->will($this->returnValue($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); $entity = new FieldInstanceConfig($values, $this->entityTypeId);
$dependencies = $entity->calculateDependencies(); $dependencies = $entity->calculateDependencies();
$this->assertContains('field.field.test_entity_type.test_field', $dependencies['entity']); $this->assertContains('field.field.test_entity_type.test_field', $dependencies['entity']);
$this->assertContains('test.test_entity_type.id', $dependencies['entity']);
} }
} }
...@@ -16,3 +16,4 @@ field_type: list_boolean ...@@ -16,3 +16,4 @@ field_type: list_boolean
dependencies: dependencies:
entity: entity:
- field.field.forum.forum_container - field.field.forum.forum_container
- taxonomy.vocabulary.forums
...@@ -53,6 +53,29 @@ public static function getInfo() { ...@@ -53,6 +53,29 @@ public static function getInfo() {
public function setUp() { public function setUp() {
parent::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. // After enabling a node access module, the access table has to be rebuild.
node_access_rebuild(); node_access_rebuild();
......
...@@ -46,6 +46,29 @@ public static function getInfo() { ...@@ -46,6 +46,29 @@ public static function getInfo() {
public function setUp() { public function setUp() {
parent::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. // After enabling a node access module, the access table has to be rebuild.
node_access_rebuild(); node_access_rebuild();
......
<?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();
}
...@@ -29,3 +29,4 @@ field_type: image ...@@ -29,3 +29,4 @@ field_type: image
dependencies: dependencies:
entity: entity:
- field.field.node.field_image - field.field.node.field_image
- node.type.article
...@@ -13,3 +13,4 @@ langcode: und ...@@ -13,3 +13,4 @@ langcode: und
dependencies: dependencies:
entity: entity:
- field.field.node.field_tags - field.field.node.field_tags
- node.type.article
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