diff --git a/core/lib/Drupal/Core/Config/ConfigManager.php b/core/lib/Drupal/Core/Config/ConfigManager.php index 2770fe32a198520eb021b0c677f1d329a1fa963e..1aca27fa55f01b4c6f24656dc3e58b76943e5405 100644 --- a/core/lib/Drupal/Core/Config/ConfigManager.php +++ b/core/lib/Drupal/Core/Config/ConfigManager.php @@ -258,7 +258,7 @@ public function getConfigDependencyManager() { /** * {@inheritdoc} */ - public function findConfigEntityDependents($type, array $names, ConfigDependencyManager $dependency_manager = NULL) { + public function findConfigEntityDependencies($type, array $names, ConfigDependencyManager $dependency_manager = NULL) { if (!$dependency_manager) { $dependency_manager = $this->getConfigDependencyManager(); } @@ -272,8 +272,8 @@ public function findConfigEntityDependents($type, array $names, ConfigDependency /** * {@inheritdoc} */ - public function findConfigEntityDependentsAsEntities($type, array $names, ConfigDependencyManager $dependency_manager = NULL) { - $dependencies = $this->findConfigEntityDependents($type, $names, $dependency_manager); + public function findConfigEntityDependenciesAsEntities($type, array $names, ConfigDependencyManager $dependency_manager = NULL) { + $dependencies = $this->findConfigEntityDependencies($type, $names, $dependency_manager); $entities = []; $definitions = $this->entityTypeManager->getDefinitions(); foreach ($dependencies as $config_name => $dependency) { @@ -299,6 +299,22 @@ public function findConfigEntityDependentsAsEntities($type, array $names, Config return $entities_to_return; } + /** + * {@inheritdoc} + */ + public function findConfigEntityDependents($type, array $names, ConfigDependencyManager $dependency_manager = NULL) { + @trigger_error('ConfigManagerInterface::findConfigEntityDependents() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Instead you should use ConfigManagerInterface::findConfigEntityDependencies(). See https://www.drupal.org/node/3225357', E_USER_DEPRECATED); + return $this->findConfigEntityDependencies($type, $names, $dependency_manager); + } + + /** + * {@inheritdoc} + */ + public function findConfigEntityDependentsAsEntities($type, array $names, ConfigDependencyManager $dependency_manager = NULL) { + @trigger_error('ConfigManagerInterface::findConfigEntityDependentsAsEntities() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Instead you should use ConfigManagerInterface::findConfigEntityDependenciesAsEntities(). See https://www.drupal.org/node/3225357', E_USER_DEPRECATED); + return $this->findConfigEntityDependenciesAsEntities($type, $names, $dependency_manager); + } + /** * {@inheritdoc} */ @@ -310,7 +326,7 @@ public function getConfigEntitiesToChangeOnDependencyRemoval($type, array $names // calling the onDependencyRemoval() method. // The list of original dependents on $names. This list never changes. - $original_dependents = $this->findConfigEntityDependentsAsEntities($type, $names, $dependency_manager); + $original_dependents = $this->findConfigEntityDependenciesAsEntities($type, $names, $dependency_manager); // The current list of dependents on $names. This list is recalculated when // calling an entity's onDependencyRemoval() method results in the entity @@ -348,7 +364,7 @@ public function getConfigEntitiesToChangeOnDependencyRemoval($type, array $names // Based on the updated data rebuild the list of current dependents. // This will remove entities that are no longer dependent after the // recalculation. - $current_dependents = $this->findConfigEntityDependentsAsEntities($type, $names, $dependency_manager); + $current_dependents = $this->findConfigEntityDependenciesAsEntities($type, $names, $dependency_manager); // Rebuild the list of entities that we need to process using the new // list of current dependents and removing any entities that we've // already processed. diff --git a/core/lib/Drupal/Core/Config/ConfigManagerInterface.php b/core/lib/Drupal/Core/Config/ConfigManagerInterface.php index 85ad99b5b925540748438ac01f4406452eff45b4..5406d10d9f926e28271d505ef82765f0c185bf62 100644 --- a/core/lib/Drupal/Core/Config/ConfigManagerInterface.php +++ b/core/lib/Drupal/Core/Config/ConfigManagerInterface.php @@ -114,7 +114,7 @@ public function getConfigDependencyManager(); * @return \Drupal\Core\Config\Entity\ConfigEntityDependency[] * An array of configuration entity dependency objects. */ - public function findConfigEntityDependents($type, array $names); + public function findConfigEntityDependencies($type, array $names); /** * Finds config entities that are dependent on extensions or entities. @@ -130,6 +130,48 @@ public function findConfigEntityDependents($type, array $names); * @return \Drupal\Core\Config\Entity\ConfigEntityInterface[] * An array of dependencies as configuration entities. */ + public function findConfigEntityDependenciesAsEntities($type, array $names); + + /** + * Deprecated method to find config entity dependencies. + * + * @param string $type + * The type of dependency being checked. Either 'module', 'theme', 'config' + * or 'content'. + * @param array $names + * The specific names to check. If $type equals 'module' or 'theme' then it + * should be a list of module names or theme names. In the case of 'config' + * or 'content' it should be a list of configuration dependency names. + * + * @return \Drupal\Core\Config\Entity\ConfigEntityDependency[] + * An array of configuration entity dependency objects. + * + * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. + * Instead you should use + * ConfigManagerInterface::findConfigEntityDependencies(). + * @see https://www.drupal.org/node/3225357 + */ + public function findConfigEntityDependents($type, array $names); + + /** + * Deprecated method to find config entity dependencies as entities. + * + * @param string $type + * The type of dependency being checked. Either 'module', 'theme', 'config' + * or 'content'. + * @param array $names + * The specific names to check. If $type equals 'module' or 'theme' then it + * should be a list of module names or theme names. In the case of 'config' + * or 'content' it should be a list of configuration dependency names. + * + * @return \Drupal\Core\Config\Entity\ConfigEntityInterface[] + * An array of dependencies as configuration entities. + * + * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. + * Instead you should use + * ConfigManagerInterface::findConfigEntityDependenciesAsEntities(). + * @see https://www.drupal.org/node/3225357 + */ public function findConfigEntityDependentsAsEntities($type, array $names); /** diff --git a/core/lib/Drupal/Core/EventSubscriber/ExcludedModulesEventSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ExcludedModulesEventSubscriber.php index a81f3e02a8cd449c5604724d44eafea95a93161b..93884d2b28e1f68e3d8dfd340d54a4015603b956 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ExcludedModulesEventSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ExcludedModulesEventSubscriber.php @@ -169,7 +169,7 @@ private function getDependentConfigNames() { } // Find all configuration that depends on the configuration found above. - foreach ($this->manager->findConfigEntityDependents('config', array_unique($config)) as $dependent) { + foreach ($this->manager->findConfigEntityDependencies('config', array_unique($config)) as $dependent) { $config[] = $dependent->getConfigDependencyName(); } diff --git a/core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php b/core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php index 593d0cbf1871400dcfd8c4675493264b5a369073..cc1a4399c9316678619a124fdfad78b25d673a17 100644 --- a/core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php +++ b/core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php @@ -305,7 +305,7 @@ public function testConfigDependencies() { $this->drupalGet($url); $this->submitForm($instance, 'Save block'); - $dependencies = \Drupal::service('config.manager')->findConfigEntityDependentsAsEntities('content', [$block->getConfigDependencyName()]); + $dependencies = \Drupal::service('config.manager')->findConfigEntityDependenciesAsEntities('content', [$block->getConfigDependencyName()]); $block_placement = reset($dependencies); $this->assertEquals($block_placement_id, $block_placement->id(), "The block placement config entity has a dependency on the block content entity."); } diff --git a/core/modules/field/tests/src/Functional/Views/FieldUITest.php b/core/modules/field/tests/src/Functional/Views/FieldUITest.php index f26fbd7caafa5336b2015c15b63c43422215000e..07ab03d177a6b80622e18e6c5776236ee08e0a50 100644 --- a/core/modules/field/tests/src/Functional/Views/FieldUITest.php +++ b/core/modules/field/tests/src/Functional/Views/FieldUITest.php @@ -98,7 +98,7 @@ public function testHandlerUI() { $this->assertEquals([], $view->field['field_name_0']->options['settings']); // Ensure that the view depends on the field storage. - $dependencies = \Drupal::service('config.manager')->findConfigEntityDependents('config', [$this->fieldStorages[0]->getConfigDependencyName()]); + $dependencies = \Drupal::service('config.manager')->findConfigEntityDependencies('config', [$this->fieldStorages[0]->getConfigDependencyName()]); $this->assertTrue(isset($dependencies['views.view.test_view_fieldapi']), 'The view is dependent on the field storage.'); } diff --git a/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php b/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php index 76904ee56da8157ce425adbea627e8032779bd2c..9917e6333f7578bc4dbc6783492f7ddd91396f30 100644 --- a/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php +++ b/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php @@ -93,7 +93,7 @@ public function assertModuleConfig($module) { } $this->assertNotEmpty($all_names); - $module_config_dependencies = \Drupal::service('config.manager')->findConfigEntityDependents('module', [$module]); + $module_config_dependencies = \Drupal::service('config.manager')->findConfigEntityDependencies('module', [$module]); // Look up each default configuration object name in the active // configuration, and if it exists, remove it from the stack. $names = $module_file_storage->listAll(); diff --git a/core/modules/system/tests/src/Functional/Module/UninstallTest.php b/core/modules/system/tests/src/Functional/Module/UninstallTest.php index 383f65ace3630527c301ad12d10acf278e60b4bc..00c08000ff1a9aada77357df394e9d1bbb731474 100644 --- a/core/modules/system/tests/src/Functional/Module/UninstallTest.php +++ b/core/modules/system/tests/src/Functional/Module/UninstallTest.php @@ -95,7 +95,7 @@ public function testUninstallPage() { // Uninstall node testing that the configuration that will be deleted is // listed. - $node_dependencies = \Drupal::service('config.manager')->findConfigEntityDependentsAsEntities('module', ['node']); + $node_dependencies = \Drupal::service('config.manager')->findConfigEntityDependenciesAsEntities('module', ['node']); $edit = []; $edit['uninstall[node]'] = TRUE; $this->drupalGet('admin/modules/uninstall'); diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php index 2221c02a7e4a4aa680f44745ab1228a4774ddc0a..22e610afec236f5dadcb06f41d21122b9a52a131 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php @@ -29,12 +29,12 @@ class ConfigDependencyTest extends EntityKernelTestBase { public function testNonEntity() { $this->installConfig(['system']); $config_manager = \Drupal::service('config.manager'); - $dependents = $config_manager->findConfigEntityDependents('module', ['system']); + $dependents = $config_manager->findConfigEntityDependencies('module', ['system']); $this->assertTrue(isset($dependents['system.site']), 'Simple configuration system.site has a UUID key even though it is not a configuration entity and therefore is found when looking for dependencies of the System module.'); // Ensure that calling - // \Drupal\Core\Config\ConfigManager::findConfigEntityDependentsAsEntities() + // \Drupal\Core\Config\ConfigManager::findConfigEntityDependenciesAsEntities() // does not try to load system.site as an entity. - $config_manager->findConfigEntityDependentsAsEntities('module', ['system']); + $config_manager->findConfigEntityDependenciesAsEntities('module', ['system']); } /** @@ -57,11 +57,11 @@ public function testDependencyManagement() { ); $entity1->save(); - $dependents = $config_manager->findConfigEntityDependents('module', ['node']); + $dependents = $config_manager->findConfigEntityDependencies('module', ['node']); $this->assertTrue(isset($dependents['config_test.dynamic.entity1']), 'config_test.dynamic.entity1 has a dependency on the Node module.'); - $dependents = $config_manager->findConfigEntityDependents('module', ['config_test']); + $dependents = $config_manager->findConfigEntityDependencies('module', ['config_test']); $this->assertTrue(isset($dependents['config_test.dynamic.entity1']), 'config_test.dynamic.entity1 has a dependency on the config_test module.'); - $dependents = $config_manager->findConfigEntityDependents('module', ['views']); + $dependents = $config_manager->findConfigEntityDependencies('module', ['views']); $this->assertFalse(isset($dependents['config_test.dynamic.entity1']), 'config_test.dynamic.entity1 does not have a dependency on the Views module.'); // Ensure that the provider of the config entity is not actually written to // the dependencies array. @@ -78,14 +78,14 @@ public function testDependencyManagement() { $entity4->save(); // Test getting $entity1's dependencies as configuration dependency objects. - $dependents = $config_manager->findConfigEntityDependents('config', [$entity1->getConfigDependencyName()]); + $dependents = $config_manager->findConfigEntityDependencies('config', [$entity1->getConfigDependencyName()]); $this->assertFalse(isset($dependents['config_test.dynamic.entity1']), 'config_test.dynamic.entity1 does not have a dependency on itself.'); $this->assertTrue(isset($dependents['config_test.dynamic.entity2']), 'config_test.dynamic.entity2 has a dependency on config_test.dynamic.entity1.'); $this->assertTrue(isset($dependents['config_test.dynamic.entity3']), 'config_test.dynamic.entity3 has a dependency on config_test.dynamic.entity1.'); $this->assertTrue(isset($dependents['config_test.dynamic.entity4']), 'config_test.dynamic.entity4 has a dependency on config_test.dynamic.entity1.'); // Test getting $entity2's dependencies as entities. - $dependents = $config_manager->findConfigEntityDependentsAsEntities('config', [$entity2->getConfigDependencyName()]); + $dependents = $config_manager->findConfigEntityDependenciesAsEntities('config', [$entity2->getConfigDependencyName()]); $dependent_ids = $this->getDependentIds($dependents); $this->assertNotContains('config_test:entity1', $dependent_ids, 'config_test.dynamic.entity1 does not have a dependency on config_test.dynamic.entity1.'); $this->assertNotContains('config_test:entity2', $dependent_ids, 'config_test.dynamic.entity2 does not have a dependency on itself.'); @@ -94,7 +94,7 @@ public function testDependencyManagement() { // Test getting node module's dependencies as configuration dependency // objects. - $dependents = $config_manager->findConfigEntityDependents('module', ['node']); + $dependents = $config_manager->findConfigEntityDependencies('module', ['node']); $this->assertTrue(isset($dependents['config_test.dynamic.entity1']), 'config_test.dynamic.entity1 has a dependency on the Node module.'); $this->assertTrue(isset($dependents['config_test.dynamic.entity2']), 'config_test.dynamic.entity2 has a dependency on the Node module.'); $this->assertTrue(isset($dependents['config_test.dynamic.entity3']), 'config_test.dynamic.entity3 has a dependency on the Node module.'); @@ -105,7 +105,7 @@ public function testDependencyManagement() { // no longer depend on node module. $entity1->setEnforcedDependencies([])->save(); $entity3->setEnforcedDependencies(['module' => ['node'], 'config' => [$entity2->getConfigDependencyName()]])->save(); - $dependents = $config_manager->findConfigEntityDependents('module', ['node']); + $dependents = $config_manager->findConfigEntityDependencies('module', ['node']); $this->assertFalse(isset($dependents['config_test.dynamic.entity1']), 'config_test.dynamic.entity1 does not have a dependency on the Node module.'); $this->assertFalse(isset($dependents['config_test.dynamic.entity2']), 'config_test.dynamic.entity2 does not have a dependency on the Node module.'); $this->assertTrue(isset($dependents['config_test.dynamic.entity3']), 'config_test.dynamic.entity3 has a dependency on the Node module.'); @@ -118,7 +118,7 @@ public function testDependencyManagement() { ]); $entity_test->save(); $entity2->setEnforcedDependencies(['config' => [$entity1->getConfigDependencyName()], 'content' => [$entity_test->getConfigDependencyName()]])->save(); - $dependents = $config_manager->findConfigEntityDependents('content', [$entity_test->getConfigDependencyName()]); + $dependents = $config_manager->findConfigEntityDependencies('content', [$entity_test->getConfigDependencyName()]); $this->assertFalse(isset($dependents['config_test.dynamic.entity1']), 'config_test.dynamic.entity1 does not have a dependency on the content entity.'); $this->assertTrue(isset($dependents['config_test.dynamic.entity2']), 'config_test.dynamic.entity2 has a dependency on the content entity.'); $this->assertTrue(isset($dependents['config_test.dynamic.entity3']), 'config_test.dynamic.entity3 has a dependency on the content entity (via entity2).'); @@ -130,7 +130,7 @@ public function testDependencyManagement() { $alt_storage->create(['id' => 'entity1', 'dependencies' => ['enforced' => ['config' => [$entity1->getConfigDependencyName()]]]])->save(); $alt_storage->create(['id' => 'entity2', 'dependencies' => ['enforced' => ['module' => ['views']]]])->save(); - $dependents = $config_manager->findConfigEntityDependentsAsEntities('config', [$entity1->getConfigDependencyName()]); + $dependents = $config_manager->findConfigEntityDependenciesAsEntities('config', [$entity1->getConfigDependencyName()]); $dependent_ids = $this->getDependentIds($dependents); $this->assertNotContains('config_test:entity1', $dependent_ids, 'config_test.dynamic.entity1 does not have a dependency on itself.'); $this->assertContains('config_test:entity2', $dependent_ids, 'config_test.dynamic.entity2 has a dependency on config_test.dynamic.entity1.'); @@ -139,7 +139,7 @@ public function testDependencyManagement() { $this->assertContains('config_query_test:entity1', $dependent_ids, 'config_query_test.dynamic.entity1 has a dependency on config_test.dynamic.entity1.'); $this->assertNotContains('config_query_test:entity2', $dependent_ids, 'config_query_test.dynamic.entity2 does not have a dependency on config_test.dynamic.entity1.'); - $dependents = $config_manager->findConfigEntityDependentsAsEntities('module', ['node', 'views']); + $dependents = $config_manager->findConfigEntityDependenciesAsEntities('module', ['node', 'views']); $dependent_ids = $this->getDependentIds($dependents); $this->assertNotContains('config_test:entity1', $dependent_ids, 'config_test.dynamic.entity1 does not have a dependency on Views or Node.'); $this->assertNotContains('config_test:entity2', $dependent_ids, 'config_test.dynamic.entity2 does not have a dependency on Views or Node.'); @@ -148,7 +148,7 @@ public function testDependencyManagement() { $this->assertNotContains('config_query_test:entity1', $dependent_ids, 'config_test.query.entity1 does not have a dependency on Views or Node.'); $this->assertContains('config_query_test:entity2', $dependent_ids, 'config_test.query.entity2 has a dependency on Views or Node.'); - $dependents = $config_manager->findConfigEntityDependentsAsEntities('module', ['config_test']); + $dependents = $config_manager->findConfigEntityDependenciesAsEntities('module', ['config_test']); $dependent_ids = $this->getDependentIds($dependents); $this->assertContains('config_test:entity1', $dependent_ids, 'config_test.dynamic.entity1 has a dependency on config_test module.'); $this->assertContains('config_test:entity2', $dependent_ids, 'config_test.dynamic.entity2 has a dependency on config_test module.'); @@ -638,6 +638,26 @@ public function testContentEntityDelete() { $this->assertTrue(empty($config_entities['unchanged']), 'No dependencies of the content entity will be unchanged.'); } + /** + * @group legacy + */ + public function testFindConfigEntityDependentsDeprecation() { + $this->expectDeprecation('ConfigManagerInterface::findConfigEntityDependents() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Instead you should use ConfigManagerInterface::findConfigEntityDependencies(). See https://www.drupal.org/node/3225357'); + /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */ + $config_manager = \Drupal::service('config.manager'); + $config_manager->findConfigEntityDependents('module', ['system']); + } + + /** + * @group legacy + */ + public function testFindConfigEntityDependentsAsEntitiesDeprecation() { + $this->expectDeprecation('ConfigManagerInterface::findConfigEntityDependentsAsEntities() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Instead you should use ConfigManagerInterface::findConfigEntityDependenciesAsEntities(). See https://www.drupal.org/node/3225357'); + /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */ + $config_manager = \Drupal::service('config.manager'); + $config_manager->findConfigEntityDependentsAsEntities('module', ['system']); + } + /** * Gets a list of identifiers from an array of configuration entities. *