summaryrefslogtreecommitdiffstats
path: root/core/modules/inline_form_errors/src/FormErrorHandler.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/inline_form_errors/src/FormErrorHandler.php')
-rw-r--r--core/modules/inline_form_errors/src/FormErrorHandler.php17
1 files changed, 14 insertions, 3 deletions
diff --git a/core/modules/inline_form_errors/src/FormErrorHandler.php b/core/modules/inline_form_errors/src/FormErrorHandler.php
index 2bcbfc6..fda5fa1 100644
--- a/core/modules/inline_form_errors/src/FormErrorHandler.php
+++ b/core/modules/inline_form_errors/src/FormErrorHandler.php
@@ -5,6 +5,7 @@ namespace Drupal\inline_form_errors;
use Drupal\Core\Form\FormElementHelper;
use Drupal\Core\Form\FormErrorHandler as CoreFormErrorHandler;
use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Routing\LinkGeneratorTrait;
use Drupal\Core\Render\RendererInterface;
@@ -29,6 +30,13 @@ class FormErrorHandler extends CoreFormErrorHandler {
protected $renderer;
/**
+ * The messenger.
+ *
+ * @var \Drupal\Core\Messenger\MessengerInterface
+ */
+ protected $messenger;
+
+ /**
* Constructs a new FormErrorHandler.
*
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
@@ -37,11 +45,14 @@ class FormErrorHandler extends CoreFormErrorHandler {
* The link generation service.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
+ * @param \Drupal\Core\Messenger\MessengerInterface $messenger
+ * The messenger.
*/
- public function __construct(TranslationInterface $string_translation, LinkGeneratorInterface $link_generator, RendererInterface $renderer) {
+ public function __construct(TranslationInterface $string_translation, LinkGeneratorInterface $link_generator, RendererInterface $renderer, MessengerInterface $messenger) {
$this->stringTranslation = $string_translation;
$this->linkGenerator = $link_generator;
$this->renderer = $renderer;
+ $this->messenger = $messenger;
}
/**
@@ -96,7 +107,7 @@ class FormErrorHandler extends CoreFormErrorHandler {
// Set normal error messages for all remaining errors.
foreach ($errors as $error) {
- $this->drupalSetMessage($error, 'error');
+ $this->messenger->addError($error);
}
if (!empty($error_links)) {
@@ -111,7 +122,7 @@ class FormErrorHandler extends CoreFormErrorHandler {
],
];
$message = $this->renderer->renderPlain($render_array);
- $this->drupalSetMessage($message, 'error');
+ $this->messenger->addError($message);
}
}