Issue #3302833 by akhil babu, b_sharpe, alexpott, oily, smustgrave: Improve PluginNotFound exception to include possible shorthand action IDs
parent
57548bace9
commit
e573df5fd0
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
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 @@ class ConfigActionManager extends DefaultPluginManager {
|
|||
$action_id = $this->getShorthandActionIdsForEntityType($entity_type)[$action_id] ?? $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());
|
||||
|
|
|
@ -76,7 +76,7 @@ class AddModerationConfigActionTest extends KernelTestBase {
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ class AddToAllBundlesConfigActionTest extends KernelTestBase {
|
|||
// 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');
|
||||
}
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ config:
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -203,6 +203,23 @@ class RecipeRunnerTest extends KernelTestBase {
|
|||
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 @@ YAML;
|
|||
|
||||
$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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue