diff --git a/core/lib/Drupal/Core/Form/ConfigFormBase.php b/core/lib/Drupal/Core/Form/ConfigFormBase.php index e7878a7db0..9781f34f99 100644 --- a/core/lib/Drupal/Core/Form/ConfigFormBase.php +++ b/core/lib/Drupal/Core/Form/ConfigFormBase.php @@ -3,6 +3,7 @@ namespace Drupal\Core\Form; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Messenger\MessengerTrait; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -10,6 +11,7 @@ */ abstract class ConfigFormBase extends FormBase { use ConfigFormBaseTrait; + use MessengerTrait; /** * Constructs a \Drupal\system\ConfigFormBase object. @@ -51,7 +53,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - drupal_set_message($this->t('The configuration options have been saved.')); + $this->messenger->addStatus($this->t('The configuration options have been saved.')); } } diff --git a/core/lib/Drupal/Core/Form/FormErrorHandler.php b/core/lib/Drupal/Core/Form/FormErrorHandler.php index 02457ce6d6..88ec061aa4 100644 --- a/core/lib/Drupal/Core/Form/FormErrorHandler.php +++ b/core/lib/Drupal/Core/Form/FormErrorHandler.php @@ -3,12 +3,14 @@ namespace Drupal\Core\Form; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Messenger\MessengerTrait; use Drupal\Core\Render\Element; /** * Handles form errors. */ class FormErrorHandler implements FormErrorHandlerInterface { + use MessengerTrait; /** * {@inheritdoc} @@ -39,7 +41,7 @@ protected function displayErrorMessages(array $form, FormStateInterface $form_st // Loop through all form errors and set an error message. foreach ($errors as $error) { - $this->drupalSetMessage($error, 'error'); + $this->messenger->addError($error); } } @@ -160,13 +162,4 @@ protected function setElementErrorsFromFormState(array &$form, FormStateInterfac $elements['#errors'] = $form_state->getError($elements); } - /** - * Wraps drupal_set_message(). - * - * @codeCoverageIgnore - */ - protected function drupalSetMessage($message = NULL, $type = 'status', $repeat = FALSE) { - drupal_set_message($message, $type, $repeat); - } - }