Skip to content
Snippets Groups Projects

Cumulative Drupal 9 Compatibility Patches

Files
7
@@ -4,6 +4,7 @@ namespace Drupal\fapiv_example\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
/**
* Implements the SimpleForm form controller.
@@ -15,6 +16,23 @@ use Drupal\Core\Form\FormStateInterface;
*/
class SimpleForm extends FormBase {
/**
* Protected member variable.
*
* @var \Drupal\Component\Utility\MessengerInterface
*/
protected $messenger;
/**
* Constructs a new SimpleForm.
*
* @param \Drupal\Component\Utility\MessengerInterface $messenger
* The messenger service.
*/
public function __construct(MessengerInterface $messenger) {
$this->messenger = $messenger;
}
/**
* Build the simple form.
*
@@ -97,7 +115,7 @@ class SimpleForm extends FormBase {
* with the title.
*/
$title = $form_state->getValue('title');
drupal_set_message($this->t('You specified a title of %title.', ['%title' => $title]));
$this->messenger()->addMessage($this->t('You specified a title of %title.', ['%title' => $title]));
}
}
Loading