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

Issue #3471271 by jurgenhaas, danielspeicher: ECA Endpoint: Ajax Requests do not receive messages

parent cea9178b
No related branches found
No related tags found
1 merge request!447Issue #3471271 by jurgenhaas: ECA Endpoint: Ajax Requests do not receive messages
Pipeline #272463 passed
......@@ -6,11 +6,13 @@ use Drupal\Core\Access\AccessResult;
use Drupal\Core\Access\AccessResultInterface;
use Drupal\Core\Ajax\AjaxHelperTrait;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\MessageCommand;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\MainContent\HtmlRenderer;
......@@ -83,6 +85,13 @@ final class EndpointController implements ContainerInjectionInterface {
*/
protected LoggerChannelInterface $logger;
/**
* The messenger.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected MessengerInterface $messenger;
/**
* {@inheritdoc}
*/
......@@ -94,7 +103,8 @@ final class EndpointController implements ContainerInjectionInterface {
$container->get('current_route_match'),
$container->get('current_user'),
$container->get('config.factory'),
$container->get('logger.channel.eca')
$container->get('logger.channel.eca'),
$container->get('messenger')
);
}
......@@ -115,8 +125,10 @@ final class EndpointController implements ContainerInjectionInterface {
* The config factory.
* @param \Drupal\Core\Logger\LoggerChannelInterface $logger
* The logger.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
*/
public function __construct(TriggerEvent $trigger_event, RendererInterface $renderer, HtmlRenderer $html_renderer, RouteMatchInterface $route_match, AccountInterface $current_user, ConfigFactoryInterface $config_factory, LoggerChannelInterface $logger) {
public function __construct(TriggerEvent $trigger_event, RendererInterface $renderer, HtmlRenderer $html_renderer, RouteMatchInterface $route_match, AccountInterface $current_user, ConfigFactoryInterface $config_factory, LoggerChannelInterface $logger, MessengerInterface $messenger) {
$this->triggerEvent = $trigger_event;
$this->renderer = $renderer;
$this->mainContentHtmlRenderer = $html_renderer;
......@@ -124,6 +136,7 @@ final class EndpointController implements ContainerInjectionInterface {
$this->currentUser = $current_user;
$this->configFactory = $config_factory;
$this->logger = $logger;
$this->messenger = $messenger;
}
/**
......@@ -189,6 +202,12 @@ final class EndpointController implements ContainerInjectionInterface {
$event = $this->triggerEvent->dispatchFromPlugin('eca_endpoint:response', $path_arguments, $request, $response, $account, $build);
if ($response instanceof AjaxResponse) {
foreach ($this->messenger->deleteAll() as $type => $type_messages) {
/** @var string[]|\Drupal\Component\Render\MarkupInterface[] $type_messages */
foreach ($type_messages as $message) {
$response->addCommand(new MessageCommand((string) $message, NULL, ['type' => $type], FALSE));
}
}
return $response;
}
if ($event instanceof RenderEventInterface) {
......
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