diff --git a/src/Form/HelpLockForm.php b/src/Form/HelpLockForm.php index 9d1ec48..9979a6e 100644 --- a/src/Form/HelpLockForm.php +++ b/src/Form/HelpLockForm.php @@ -4,7 +4,10 @@ namespace Drupal\config_help\Form; use Drupal\Core\Entity\EntityConfirmFormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Messenger\MessengerInterface; +use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Url; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a form for confirming locking of a help topic. @@ -12,6 +15,36 @@ use Drupal\Core\Url; class HelpLockForm extends EntityConfirmFormBase { /** + * The Messenger service. + * + * @var \Drupal\Core\Messenger\MessengerInterface + */ + protected $messenger; + + /** + * Constructs the help topic lock form. + * + * @param \Drupal\Core\Messenger\MessengerInterface $messenger + * The messenger service. + * @param TranslationInterface $string_translation + * The translation manager. + */ + public function __construct(MessengerInterface $messenger, TranslationInterface $string_translation) { + $this->messenger = $messenger; + $this->stringTranslation = $string_translation; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('messenger'), + $container->get('string_translation') + ); + } + + /** * {@inheritdoc} */ public function getQuestion() { @@ -43,7 +76,7 @@ class HelpLockForm extends EntityConfirmFormBase { $ops_link = $this->entity->toLink($this->t('View'), 'canonical')->toString(); $args = ['@link' => $link]; $message = $this->t('The help topic @link has been locked.', $args); - drupal_set_message($message); + $this->messenger->addMessage($message); $this->getLogger('config_help')->notice('The help topic @link has been locked.', $args + [ 'link' => $ops_link, ]); diff --git a/src/Form/HelpTopicForm.php b/src/Form/HelpTopicForm.php index 4adcdac..b34f8ec 100644 --- a/src/Form/HelpTopicForm.php +++ b/src/Form/HelpTopicForm.php @@ -11,6 +11,8 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ThemeHandlerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\Messenger\MessengerInterface; +use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -47,6 +49,13 @@ class HelpTopicForm extends EntityForm { protected $themeHandler; /** + * The Messenger service. + * + * @var \Drupal\Core\Messenger\MessengerInterface + */ + protected $messenger; + + /** * Constructs a new help topic form. * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager @@ -55,12 +64,18 @@ class HelpTopicForm extends EntityForm { * The module handler. * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler * The theme handler. + * @param \Drupal\Core\Messenger\MessengerInterface $messenger + * The messenger service. + * @param TranslationInterface $string_translation + * The translation manager. */ - public function __construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) { + public function __construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, MessengerInterface $messenger, TranslationInterface $string_translation) { $this->helpStorage = $entity_type_manager->getStorage('help_topic'); $this->helpViewBuilder = $entity_type_manager->getViewBuilder('help_topic'); $this->moduleHandler = $module_handler; $this->themeHandler = $theme_handler; + $this->messenger = $messenger; + $this->stringTranslation = $string_translation; } /** @@ -70,7 +85,9 @@ class HelpTopicForm extends EntityForm { return new static( $container->get('entity_type.manager'), $container->get('module_handler'), - $container->get('theme_handler') + $container->get('theme_handler'), + $container->get('messenger'), + $container->get('string_translation') ); } @@ -333,14 +350,14 @@ class HelpTopicForm extends EntityForm { $args = ['@link' => $link]; if ($status == SAVED_UPDATED) { $message = $this->t('The help topic @link has been updated.', $args); - drupal_set_message($message); + $this->messenger->addMessage($message); $this->getLogger('config_help')->notice('The help topic @link has been updated.', $args + [ 'link' => $ops_link, ]); } else { $message = $this->t('The help topic @link has been added.', $args); - drupal_set_message($message); + $this->messenger->addMessage($message); $this->getLogger('config_help')->notice('The help topic @link has been added.', $args + [ 'link' => $ops_link, ]); diff --git a/src/Form/HelpUnlockForm.php b/src/Form/HelpUnlockForm.php index 208e1cd..8ca02fa 100644 --- a/src/Form/HelpUnlockForm.php +++ b/src/Form/HelpUnlockForm.php @@ -4,7 +4,10 @@ namespace Drupal\config_help\Form; use Drupal\Core\Entity\EntityConfirmFormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Messenger\MessengerInterface; +use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Url; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a form for confirming unlocking of a help topic. @@ -12,6 +15,36 @@ use Drupal\Core\Url; class HelpUnlockForm extends EntityConfirmFormBase { /** + * The Messenger service. + * + * @var \Drupal\Core\Messenger\MessengerInterface + */ + protected $messenger; + + /** + * Constructs the help topic unlock form. + * + * @param \Drupal\Core\Messenger\MessengerInterface $messenger + * The messenger service. + * @param TranslationInterface $string_translation + * The translation manager. + */ + public function __construct(MessengerInterface $messenger, TranslationInterface $string_translation) { + $this->messenger = $messenger; + $this->stringTranslation = $string_translation; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('messenger'), + $container->get('string_translation') + ); + } + + /** * {@inheritdoc} */ public function getQuestion() { @@ -43,7 +76,7 @@ class HelpUnlockForm extends EntityConfirmFormBase { $ops_link = $this->entity->toLink($this->t('View'), 'canonical')->toString(); $args = ['@link' => $link]; $message = $this->t('The help topic @link has been unlocked.', $args); - drupal_set_message($message); + $this->messenger->addMessage($message); $this->getLogger('config_help')->notice('The help topic @link has been unlocked.', $args + [ 'link' => $ops_link, ]);