I am using the Message module with Drupal 8 to log information.

I was able to get the date and time in the messages produced by adding a token of the date and time , but I want to add a customized message that is different each time. How can I do this? this is the code I am using:

 $message = Message::create(['template' => 'sfbu_progress']);  

How can I add a customized message to each message created? For Example I want it to say "This file 444.pdf was successfully uploaded" or "this file 888.pdf was missing ".


1 Answer 1


Checkout the setArguments(), getText() and the processArguments() function in the Message Entity class:

$message = Message::create(['template' => 'sfbu_progress']);
   '@my_argument' => 'my_argument_value',

And in your Template which you create over the UI write the @my_argument to the textarea. It should be replaced with your text.

It is also possible to add an callback function as argument. Therefor checkout the declaration of the argument property in MessageTemplate Entity class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.