Skip to content

Instantly share code, notes, and snippets.

@manojiksula
Forked from signalpoint/example.php
Created May 10, 2020 09:09
Show Gist options
  • Save manojiksula/96b3feb52aaa668a32fab11f96093f50 to your computer and use it in GitHub Desktop.
Save manojiksula/96b3feb52aaa668a32fab11f96093f50 to your computer and use it in GitHub Desktop.
Drupal 8 Set Message Example
<?php
// The drupal_set_message() function is being deprecated!
// @see https://api.drupal.org/api/drupal/core%21includes%21bootstrap.inc/function/drupal_set_message/8.5.x
// > Deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
// > Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead.
// In some custom code.
\Drupal::messenger()->addMessage('Say something else');
// When trying to print out a simple var.
\Drupal::messenger()->addMessage(print_r($stuff, TRUE));
// In a Drupal 8 Form's submitForm() handler:
$this->messenger()->addMessage($this->t('Hello world.'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment