Skip to content
Snippets Groups Projects
Commit 03e9abe6 authored by Jürgen Haas's avatar Jürgen Haas
Browse files

Issue #3314320 by jurgenhaas: Broken pre-configured actions with missing plugins may cause WSOD

parent e7bfd4a7
No related branches found
Tags 8.x-2.0-beta1
No related merge requests found
......@@ -3,7 +3,9 @@
namespace Drupal\eca\Plugin\Action;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Config\Entity\ConfigEntityStorageInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\eca\PluginManager\Action;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -34,6 +36,13 @@ class PreConfiguredActionDeriver extends DeriverBase implements ContainerDeriver
*/
protected Action $actionPluginManager;
/**
* The logger channel.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected LoggerChannelInterface $logger;
/**
* {@inheritdoc}
*/
......@@ -41,6 +50,7 @@ class PreConfiguredActionDeriver extends DeriverBase implements ContainerDeriver
$instance = new static();
$instance->setActionEntityStorage($container->get('entity_type.manager')->getStorage('action'));
$instance->setActionPluginManager($container->get('plugin.manager.eca.action'));
$instance->setLogger($container->get('logger.channel.eca'));
return $instance;
}
......@@ -58,12 +68,21 @@ class PreConfiguredActionDeriver extends DeriverBase implements ContainerDeriver
$this->derivatives = [];
/** @var \Drupal\system\Entity\Action $action */
foreach ($this->actionEntityStorage->loadMultiple() as $action) {
try {
$pluginDefinition = $action->getPluginDefinition();
}
catch (PluginNotFoundException $ex) {
$this->logger->error('Preconfigured action with a missing plugin found. You should delete that action with "drush config:delete system.action.@plugin". @msg', [
'@plugin' => $action->id(),
'@msg' => $ex->getMessage(),
]);
continue;
}
$id = $action->id();
$this->derivatives[$id] = [
'label' => 'Pre-configured: ' . $action->label(),
'action_entity_id' => $id,
] + $base_plugin_definition;
$pluginDefinition = $action->getPluginDefinition();
foreach (['type', 'confirm_form_route_name'] as $key) {
if (isset($pluginDefinition[$key])) {
$this->derivatives[$action->id()][$key] = $pluginDefinition[$key];
......@@ -100,4 +119,14 @@ class PreConfiguredActionDeriver extends DeriverBase implements ContainerDeriver
$this->actionPluginManager = $manager;
}
/**
* Set the logger channel.
*
* @param \Drupal\Core\Logger\LoggerChannelInterface $logger
* The logger channel.
*/
public function setLogger(LoggerChannelInterface $logger): void {
$this->logger = $logger;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment