diff --git a/core/lib/Drupal/Core/Config/Action/ConfigActionManager.php b/core/lib/Drupal/Core/Config/Action/ConfigActionManager.php index 0bd38dd26d549f4cbb4744a87637374e0f6eba13..00952fa3657bd2b4e94f65bd3faec1ae71aa9cf8 100644 --- a/core/lib/Drupal/Core/Config/Action/ConfigActionManager.php +++ b/core/lib/Drupal/Core/Config/Action/ConfigActionManager.php @@ -4,6 +4,7 @@ namespace Drupal\Core\Config\Action; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\Action\Attribute\ConfigAction; @@ -137,8 +138,20 @@ public function applyAction(string $action_id, string $configName, mixed $data): $action_id = $this->getShorthandActionIdsForEntityType($entity_type)[$action_id] ?? $action_id; } } - /** @var \Drupal\Core\Config\Action\ConfigActionPluginInterface $action */ - $action = $this->createInstance($action_id); + try { + /** @var \Drupal\Core\Config\Action\ConfigActionPluginInterface $action */ + $action = $this->createInstance($action_id); + } + catch (PluginNotFoundException $e) { + $entity_type = $this->configManager->getEntityTypeIdByName($configName); + if ($entity_type) { + $action_ids = $this->getShorthandActionIdsForEntityType($entity_type); + $valid_ids = implode(', ', array_keys($action_ids)); + throw new PluginNotFoundException($action_id, sprintf('The "%s" entity does not support the "%s" config action. Valid config actions for %s are: %s', $entity_type, $action_id, $entity_type, $valid_ids)); + } + throw $e; + } + foreach ($this->getConfigNamesMatchingExpression($configName) as $name) { $action->apply($name, $data); $typed_config = $this->typedConfig->createFromNameAndData($name, $this->configFactory->get($name)->getRawData()); diff --git a/core/modules/block/tests/src/Kernel/ConfigActionsTest.php b/core/modules/block/tests/src/Kernel/ConfigActionsTest.php index 37fbe780cc7274fa15f62a4c1758dce66e90eaf2..88bdb8afef8e4bb5ce2029898d35e2960e2dcd86 100644 --- a/core/modules/block/tests/src/Kernel/ConfigActionsTest.php +++ b/core/modules/block/tests/src/Kernel/ConfigActionsTest.php @@ -73,7 +73,7 @@ public function testEntityMethodActions(): void { */ public function testPlaceBlockActionOnlyWorksOnBlocks(string $action): void { $this->expectException(PluginNotFoundException::class); - $this->expectExceptionMessage("The \"$action\" plugin does not exist."); + $this->expectExceptionMessage("The \"user_role\" entity does not support the \"$action\" config action."); $this->configActionManager->applyAction($action, 'user.role.anonymous', []); } diff --git a/core/modules/content_moderation/tests/src/Kernel/ConfigAction/AddModerationConfigActionTest.php b/core/modules/content_moderation/tests/src/Kernel/ConfigAction/AddModerationConfigActionTest.php index 4d5afd395e2ab2bf133a13125d69c362f5987fb1..a48ec826cc7fee81e9ea591c88c400be3cd537a4 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ConfigAction/AddModerationConfigActionTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ConfigAction/AddModerationConfigActionTest.php @@ -76,7 +76,7 @@ public function testWorkflowMustBeContentModeration(): void { public function testActionOnlyTargetsWorkflows(): void { $recipe = $this->createRecipe('user.role.anonymous'); $this->expectException(PluginNotFoundException::class); - $this->expectExceptionMessage('The "addNodeTypes" plugin does not exist.'); + $this->expectExceptionMessage('The "user_role" entity does not support the "addNodeTypes" config action.'); RecipeRunner::processRecipe($recipe); } diff --git a/core/modules/field/tests/src/Kernel/AddToAllBundlesConfigActionTest.php b/core/modules/field/tests/src/Kernel/AddToAllBundlesConfigActionTest.php index 4f6ec730877deadad06456ec680cf5d246b9944b..0c849c246ff20ee4d14250c927372fb6c831840d 100644 --- a/core/modules/field/tests/src/Kernel/AddToAllBundlesConfigActionTest.php +++ b/core/modules/field/tests/src/Kernel/AddToAllBundlesConfigActionTest.php @@ -74,7 +74,7 @@ public function testInstantiateNewFieldOnAllBundles(): void { // Expect an error when the 'addToAllBundles' action is invoked on anything // other than a field storage config entity. $this->expectException(PluginNotFoundException::class); - $this->expectExceptionMessage('The "addToAllBundles" plugin does not exist.'); + $this->expectExceptionMessage('The "user_role" entity does not support the "addToAllBundles" config action.'); $this->applyAction('user.role.anonymous'); } diff --git a/core/tests/Drupal/KernelTests/Core/Recipe/PermissionsPerBundleTest.php b/core/tests/Drupal/KernelTests/Core/Recipe/PermissionsPerBundleTest.php index c9465a31d49f84aa5933e715fcede6241b641d9d..0a702e0322cc86f18ef9e41c60edec3f8376b0ce 100644 --- a/core/tests/Drupal/KernelTests/Core/Recipe/PermissionsPerBundleTest.php +++ b/core/tests/Drupal/KernelTests/Core/Recipe/PermissionsPerBundleTest.php @@ -124,7 +124,7 @@ public function testActionIsOnlyAvailableToUserRoles(): void { YAML; $this->expectException(PluginNotFoundException::class); - $this->expectExceptionMessage('The "grantPermissionsForEachNodeType" plugin does not exist.'); + $this->expectExceptionMessage('The "field_storage_config" entity does not support the "grantPermissionsForEachNodeType" config action.'); $this->applyRecipeFromString($recipe_data); } diff --git a/core/tests/Drupal/KernelTests/Core/Recipe/RecipeRunnerTest.php b/core/tests/Drupal/KernelTests/Core/Recipe/RecipeRunnerTest.php index 64d94653c1388b661c7ba20de3c6ec7598b9b353..871b040527d798ab32e040a5d3a37b9e1e6c850d 100644 --- a/core/tests/Drupal/KernelTests/Core/Recipe/RecipeRunnerTest.php +++ b/core/tests/Drupal/KernelTests/Core/Recipe/RecipeRunnerTest.php @@ -203,6 +203,23 @@ public function testConfigActionsPreExistingConfig() :void { public function testInvalidConfigAction() :void { $recipe_data = <<<YAML name: Invalid config action +install: + - config_test +config: + actions: + config_test.system: + setFoo: 'Bar' +YAML; + + $recipe = $this->createRecipe($recipe_data); + $this->expectException(PluginNotFoundException::class); + $this->expectExceptionMessage('The "setFoo" plugin does not exist.'); + RecipeRunner::processRecipe($recipe); + } + + public function testInvalidConfigActionAppliedOnConfigEntity() :void { + $recipe_data = <<<YAML +name: Invalid config action install: - config_test config: @@ -215,7 +232,7 @@ public function testInvalidConfigAction() :void { $recipe = $this->createRecipe($recipe_data); $this->expectException(PluginNotFoundException::class); - $this->expectExceptionMessage('The "setBody" plugin does not exist.'); + $this->expectExceptionMessage('The "config_test" entity does not support the "setBody" config action.'); RecipeRunner::processRecipe($recipe); }