diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 4dd5231..7e5c3a4 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -342,7 +342,7 @@ public function preSave(EntityStorageInterface $storage) { throw new ConfigDuplicateUUIDException("Attempt to save a configuration entity '{$this->id()}' with UUID '{$this->uuid()}' when this entity already exists with UUID '{$original->uuid()}'"); } } - if (!$this->isSyncing() && !$this->trustedData) { + if (!$this->isSyncing()) { // Ensure the correct dependencies are present. If the configuration is // being written during a configuration synchronization then there is no // need to recalculate the dependencies. diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php index 66c0b00..b84a220 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -416,6 +416,8 @@ public static function calculateDependencies(FieldDefinitionInterface $field_def $manager = \Drupal::entityManager(); $target_entity_type = $manager->getDefinition($field_definition->getFieldStorageDefinition()->getSetting('target_type')); + $dependencies['module'][] = $target_entity_type->getProvider(); + // Depend on default values entity types configurations. if ($default_value = $field_definition->getDefaultValueLiteral()) { foreach ($default_value as $value) { diff --git a/core/modules/book/config/install/core.entity_view_mode.node.print.yml b/core/modules/book/config/install/core.entity_view_mode.node.print.yml index d695ac5..d615b03 100644 --- a/core/modules/book/config/install/core.entity_view_mode.node.print.yml +++ b/core/modules/book/config/install/core.entity_view_mode.node.print.yml @@ -1,11 +1,11 @@ langcode: en status: false dependencies: - module: - - node enforced: module: - book + module: + - node id: node.print label: Print targetEntityType: node diff --git a/core/modules/config/src/Tests/ConfigInstallTest.php b/core/modules/config/src/Tests/ConfigInstallTest.php index 2d09548..7358e65 100644 --- a/core/modules/config/src/Tests/ConfigInstallTest.php +++ b/core/modules/config/src/Tests/ConfigInstallTest.php @@ -211,7 +211,11 @@ public function testDependencyChecking() { } $this->installModules(['config_other_module_config_test']); $this->installModules(['config_install_dependency_test']); - $this->assertTrue(entity_load('config_test', 'other_module_test_with_dependency'), 'The config_test.dynamic.other_module_test_with_dependency configuration has been created during install.'); + $entity = \Drupal::entityManager()->getStorage('config_test')->load('other_module_test_with_dependency'); + $this->assertTrue($entity, 'The config_test.dynamic.other_module_test_with_dependency configuration has been created during install.'); + // Ensure that dependencies can be added during module installation by + // hooks. + $this->assertIdentical('config_install_dependency_test', $entity->getDependencies()['module'][0]); } /** diff --git a/core/modules/config/tests/config_install_dependency_test/config_install_dependency_test.module b/core/modules/config/tests/config_install_dependency_test/config_install_dependency_test.module new file mode 100644 index 0000000..08a1697 --- /dev/null +++ b/core/modules/config/tests/config_install_dependency_test/config_install_dependency_test.module @@ -0,0 +1,15 @@ +setEnforcedDependencies(['module' => ['config_install_dependency_test']]); +} diff --git a/core/modules/forum/config/install/core.entity_view_display.node.forum.default.yml b/core/modules/forum/config/install/core.entity_view_display.node.forum.default.yml index 69fdb79..39389a5 100644 --- a/core/modules/forum/config/install/core.entity_view_display.node.forum.default.yml +++ b/core/modules/forum/config/install/core.entity_view_display.node.forum.default.yml @@ -8,7 +8,6 @@ dependencies: - node.type.forum module: - comment - - taxonomy - text - user id: node.forum.default diff --git a/core/modules/forum/config/install/core.entity_view_display.node.forum.teaser.yml b/core/modules/forum/config/install/core.entity_view_display.node.forum.teaser.yml index 6eb1a0c..4405e71 100644 --- a/core/modules/forum/config/install/core.entity_view_display.node.forum.teaser.yml +++ b/core/modules/forum/config/install/core.entity_view_display.node.forum.teaser.yml @@ -8,7 +8,6 @@ dependencies: - field.field.node.forum.taxonomy_forums - node.type.forum module: - - taxonomy - text - user id: node.forum.teaser diff --git a/core/modules/forum/config/install/field.field.node.forum.taxonomy_forums.yml b/core/modules/forum/config/install/field.field.node.forum.taxonomy_forums.yml index 1f7bc5c..ae0d464 100644 --- a/core/modules/forum/config/install/field.field.node.forum.taxonomy_forums.yml +++ b/core/modules/forum/config/install/field.field.node.forum.taxonomy_forums.yml @@ -4,6 +4,7 @@ dependencies: config: - field.storage.node.taxonomy_forums - node.type.forum + - taxonomy.vocabulary.forums module: - taxonomy id: node.forum.taxonomy_forums diff --git a/core/modules/forum/config/install/field.storage.node.taxonomy_forums.yml b/core/modules/forum/config/install/field.storage.node.taxonomy_forums.yml index f37ea9e..ddf3183 100644 --- a/core/modules/forum/config/install/field.storage.node.taxonomy_forums.yml +++ b/core/modules/forum/config/install/field.storage.node.taxonomy_forums.yml @@ -3,7 +3,6 @@ status: true dependencies: module: - node - - taxonomy id: node.taxonomy_forums field_name: taxonomy_forums entity_type: node diff --git a/core/modules/system/src/Tests/Entity/EntityReferenceFieldTest.php b/core/modules/system/src/Tests/Entity/EntityReferenceFieldTest.php index b78dff29..0aec9eb 100644 --- a/core/modules/system/src/Tests/Entity/EntityReferenceFieldTest.php +++ b/core/modules/system/src/Tests/Entity/EntityReferenceFieldTest.php @@ -14,6 +14,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait; use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\user\Entity\Role; use Drupal\user\Entity\User; use Drupal\user\RoleInterface; @@ -406,4 +407,35 @@ public function testTargetEntityNoLoad() { } } + /** + * Tests the dependencies entity reference fields are created with. + */ + public function testEntityReferenceFieldDependencies() { + $field_name = 'user_reference_field'; + $entity_type = 'entity_test'; + + $field_storage = FieldStorageConfig::create(array( + 'field_name' => $field_name, + 'type' => 'entity_reference', + 'entity_type' => $entity_type, + 'settings' => array( + 'target_type' => 'user', + ), + )); + $field_storage->save(); + $this->assertEqual(['module' => ['entity_test']], $field_storage->getDependencies()); + + $field = FieldConfig::create(array( + 'field_name' => $field_name, + 'entity_type' => $entity_type, + 'bundle' => 'entity_test', + 'label' => $field_name, + 'settings' => array( + 'handler' => 'default' + ), + )); + $field->save(); + $this->assertEqual(['config' => ['field.storage.entity_test.user_reference_field'], 'module' => ['entity_test', 'user']], $field->getDependencies()); + } + } diff --git a/core/modules/system/src/Tests/Update/RecalculatedDependencyTest.php b/core/modules/system/src/Tests/Update/RecalculatedDependencyTest.php new file mode 100644 index 0000000..36fa215 --- /dev/null +++ b/core/modules/system/src/Tests/Update/RecalculatedDependencyTest.php @@ -0,0 +1,45 @@ +databaseDumpFiles = [ + __DIR__ . '/../../../tests/fixtures/update/drupal-8.bare.standard.php.gz', + ]; + } + + /** + * Ensures that the entities are resaved so they have the new dependency. + */ + public function testUpdate() { + $this->runUpdates(); + + $data = \Drupal::config('field.field.node.article.field_tags')->get(); + $this->assertEqual(['taxonomy'], $data['dependencies']['module']); + + $data = \Drupal::config('field.field.user.user.user_picture')->get(); + $this->assertEqual(['file', 'image', 'user'], $data['dependencies']['module']); + + $data = \Drupal::config('field.storage.node.field_image')->get(); + $this->assertEqual(['image', 'node'], $data['dependencies']['module']); + + $data = \Drupal::config('field.storage.node.field_tags')->get(); + $this->assertEqual(['node'], $data['dependencies']['module']); + } + +} diff --git a/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php b/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php index 1d6375e..e031df3 100644 --- a/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php +++ b/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php @@ -64,6 +64,7 @@ public function testPostUpdate() { 'field_post_update_save_custom_storage_property', 'field_post_update_entity_reference_handler_setting', 'system_post_update_fix_enforced_dependencies', + 'system_post_update_recalculate_dependencies_for_installed_config_entities', 'views_post_update_update_cacheability_metadata', ], $updates); $this->assertEqual($updates, $key_value->get('existing_updates')); diff --git a/core/modules/system/system.post_update.php b/core/modules/system/system.post_update.php index 3a141ce..46cfda2 100644 --- a/core/modules/system/system.post_update.php +++ b/core/modules/system/system.post_update.php @@ -4,6 +4,9 @@ * @file * Post update functions for System. */ +use Drupal\Core\Config\FileStorage; +use Drupal\Core\Config\InstallStorage; +use Drupal\Core\Config\StorageInterface; /** * @addtogroup updates-8.0.0-beta @@ -31,5 +34,30 @@ function system_post_update_fix_enforced_dependencies() { } /** + * Re-save all config entities that got installed at some point. + * + * Drupal forgot to recalculate the dependencies for them, + * see https://www.drupal.org/node/2520526, so we resave to recalculate them. + */ +function system_post_update_recalculate_dependencies_for_installed_config_entities() { + /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */ + $config_manager = \Drupal::service('config.manager'); + + // Loads scan all module install folders and resave the entities in there. + $modules = array_keys(\Drupal::moduleHandler()->getModuleList()); + foreach ($modules as $module) { + $default_install_path = drupal_get_path('module', $module) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY; + $storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION); + $config_names = $storage->listAll(); + + foreach ($config_names as $config_name) { + if ($entity = $config_manager->loadConfigEntityByName($config_name)) { + $entity->save(); + } + } + } +} + +/** * @} End of "addtogroup updates-8.0.0-beta". */ diff --git a/core/profiles/standard/config/install/field.field.node.article.field_image.yml b/core/profiles/standard/config/install/field.field.node.article.field_image.yml index b69d603..4c90f17 100644 --- a/core/profiles/standard/config/install/field.field.node.article.field_image.yml +++ b/core/profiles/standard/config/install/field.field.node.article.field_image.yml @@ -5,6 +5,7 @@ dependencies: - field.storage.node.field_image - node.type.article module: + - file - image id: node.article.field_image field_name: field_image diff --git a/core/profiles/standard/config/install/field.field.node.article.field_tags.yml b/core/profiles/standard/config/install/field.field.node.article.field_tags.yml index c49c64f..e86bb5d 100644 --- a/core/profiles/standard/config/install/field.field.node.article.field_tags.yml +++ b/core/profiles/standard/config/install/field.field.node.article.field_tags.yml @@ -4,6 +4,9 @@ dependencies: config: - field.storage.node.field_tags - node.type.article + - taxonomy.vocabulary.tags + module: + - taxonomy id: node.article.field_tags field_name: field_tags entity_type: node diff --git a/core/profiles/standard/config/install/field.field.user.user.user_picture.yml b/core/profiles/standard/config/install/field.field.user.user.user_picture.yml index 5145085..560f363 100644 --- a/core/profiles/standard/config/install/field.field.user.user.user_picture.yml +++ b/core/profiles/standard/config/install/field.field.user.user.user_picture.yml @@ -4,6 +4,7 @@ dependencies: config: - field.storage.user.user_picture module: + - file - image - user id: user.user.user_picture diff --git a/core/profiles/standard/config/install/field.storage.node.field_image.yml b/core/profiles/standard/config/install/field.storage.node.field_image.yml index 8c2f981..bce946d 100644 --- a/core/profiles/standard/config/install/field.storage.node.field_image.yml +++ b/core/profiles/standard/config/install/field.storage.node.field_image.yml @@ -2,8 +2,8 @@ langcode: en status: true dependencies: module: - - node - image + - node id: node.field_image field_name: field_image entity_type: node diff --git a/core/profiles/standard/config/install/field.storage.node.field_tags.yml b/core/profiles/standard/config/install/field.storage.node.field_tags.yml index 73f821f..69b9edc 100644 --- a/core/profiles/standard/config/install/field.storage.node.field_tags.yml +++ b/core/profiles/standard/config/install/field.storage.node.field_tags.yml @@ -3,7 +3,6 @@ status: true dependencies: module: - node - - taxonomy id: node.field_tags field_name: field_tags entity_type: node