- 🇮🇳India kmani
Use messenger interface to display messages while redirecting
use Drupal\Core\Messenger\MessengerInterface;
$this->messenger->addMessage('This is a warning message (orange)', TRUE);
I was using drupal_set_message and now MessengerInterface::addMessage to display status and warning messages from my custom modules.
I noticed anonymous users did not see these messages.
When removing my PHP header redirects, the messages do show up.
The strange part is that it does work for users that are logged in even when setting a PHP header redirect.
Is this intended?
What is the proper way to do this?
class MyCustomController extends ControllerBase {
$this->messenger()->addMessage('This is a test.');
header('Location: ' . '/');
die();
}
Fixed
8.8 ⚰️
Last updated
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Use messenger interface to display messages while redirecting
use Drupal\Core\Messenger\MessengerInterface;
$this->messenger->addMessage('This is a warning message (orange)', TRUE);