You are here

public function TwigExtension::drupalSetMessage in Twig Tweak 8

Sets a message to display to the user.

Parameters

string|\Drupal\Component\Render\MarkupInterface $message: (optional) The translated message to be displayed to the user.

string $type: (optional) The message's type. Defaults to 'status'.

bool $repeat: (optional) If this is FALSE and the message is already set, then the message will not be repeated. Defaults to FALSE.

Return value

array A render array to disable caching.

File

src/TwigExtension.php, line 351

Class

TwigExtension
Twig extension with some useful functions and filters.

Namespace

Drupal\twig_tweak

Code

public function drupalSetMessage($message = NULL, $type = 'status', $repeat = FALSE) {
  \Drupal::messenger()
    ->addMessage($message, $type, $repeat);
  $build['#cache']['max-age'] = 0;
  return $build;
}