On this page
Subscribe Example
Last updated on
29 January 2024
This documentation needs work. See "Help improve this page" in the sidebar.
Simple
An example of sending messages to subscribers.
/**
* Implements hook_node_update().
*/
function message_subscribe_example_node_update(NodeInterface $node) {
$message = Message::create([
'template' => 'node_update',
'uid' => $node->getOwnerId(),
]);
$message->set('field_node_reference', $node);
$message->set('field_published', $node->isPublished());
$message->save();
// Send message to subscribers about changes to the node.
$subscribers = \Drupal::service('message_subscribe.subscribers');
$subscribers->sendMessage($node, $message);
}Help improve this page
Page status: Needs work
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.