diff --git a/core/lib/Drupal/Core/Field/FieldItemInterface.php b/core/lib/Drupal/Core/Field/FieldItemInterface.php index 592b3c7..ad42da5 100644 --- a/core/lib/Drupal/Core/Field/FieldItemInterface.php +++ b/core/lib/Drupal/Core/Field/FieldItemInterface.php @@ -427,9 +427,9 @@ public static function calculateDependencies(FieldDefinitionInterface $field_def * return an array of dependencies listing the module that provides the entity * type. * - * Dependencies added here affect the storage and therefore are always - * considered hard dependencies. If the dependency is removed the field - * storage must be deleted. + * Dependencies returned from this method are stored in field storage + * configuration and are always considered hard dependencies. If the + * dependency is removed the field storage configuration must be deleted. * * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $field_storage_definition * The field storage definition. diff --git a/core/modules/system/src/Tests/Update/RecalculatedDependencyTest.php b/core/modules/system/src/Tests/Update/RecalculatedDependencyTest.php index 53a832a..820f9af 100644 --- a/core/modules/system/src/Tests/Update/RecalculatedDependencyTest.php +++ b/core/modules/system/src/Tests/Update/RecalculatedDependencyTest.php @@ -27,8 +27,28 @@ protected function setDatabaseDumpFiles() { * Ensures that the entities are resaved so they have the new dependency. */ public function testUpdate() { + // Test the configuration pre update. + $data = \Drupal::config('field.field.node.article.field_tags')->get(); + $this->assertEqual(['entity_reference'], $data['dependencies']['module']); + $this->assertEqual([ + 'field.storage.node.field_tags', + 'node.type.article', + ], $data['dependencies']['config']); + + $data = \Drupal::config('field.field.user.user.user_picture')->get(); + $this->assertFalse(isset($data['dependencies']['module'])); + + $data = \Drupal::config('field.storage.node.field_image')->get(); + $this->assertEqual(['node', 'image'], $data['dependencies']['module']); + + // Explicitly break an optional configuration dependencies to ensure it is + // recalculated. + \Drupal::configFactory()->getEditable('search.page.node_search')->clear('dependencies')->save(); + + // Run the updates. $this->runUpdates(); + // Test the configuration post update. $data = \Drupal::config('field.field.node.article.field_tags')->get(); $this->assertFalse(isset($data['dependencies']['module'])); $this->assertEqual([ @@ -37,14 +57,14 @@ public function testUpdate() { 'taxonomy.vocabulary.tags' ], $data['dependencies']['config']); - $data = \Drupal::config('field.storage.node.field_tags')->get(); - $this->assertEqual(['node', 'taxonomy'], $data['dependencies']['module']); - $data = \Drupal::config('field.field.user.user.user_picture')->get(); $this->assertEqual(['image', 'user'], $data['dependencies']['module']); $data = \Drupal::config('field.storage.node.field_image')->get(); $this->assertEqual(['file', 'image', 'node'], $data['dependencies']['module']); + + $data = \Drupal::config('search.page.node_search')->get(); + $this->assertEqual(['node'], $data['dependencies']['module']); } } diff --git a/core/modules/system/system.post_update.php b/core/modules/system/system.post_update.php index 46cfda2..d1dc79e 100644 --- a/core/modules/system/system.post_update.php +++ b/core/modules/system/system.post_update.php @@ -36,24 +36,26 @@ 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. + * Drupal did not calculate dependencies on install, so recalculate them by + * saving all matching configuration entities. + * + * @see https://www.drupal.org/node/2520526 */ 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(); - } + // Scan all module install folders and resave the entities in there. This + // includes uninstalled modulees too as potentially they provided + // configuration which did not depend on themselves. + $install_storage = new InstallStorage(); + $config_names = $install_storage->listAll(); + $install_storage = new InstallStorage(InstallStorage::CONFIG_OPTIONAL_DIRECTORY); + $config_names = array_merge($config_names, $install_storage->listAll()); + + foreach ($config_names as $config_name) { + if ($entity = $config_manager->loadConfigEntityByName($config_name)) { + $entity->save(); } } }