Skip to content

Instantly share code, notes, and snippets.

@amitaibu
Created September 25, 2016 14:22
Show Gist options
  • Save amitaibu/cb1933a663fc902271f10bc8617dbbd1 to your computer and use it in GitHub Desktop.
Save amitaibu/cb1933a663fc902271f10bc8617dbbd1 to your computer and use it in GitHub Desktop.
<?php
/**
* Implements hook_node_insert().
*/
function example_node_insert(\Drupal\node\NodeInterface $node) {
$message = Message::create(['template' => 'node_created']);
$arguments = [
'@url' => $node->toUrl()->setAbsolute()->toString(),
];
$message
->set('field_node', $node)
->setOwner($node->getOwner())
->setArguments($arguments);
// Send via message notify, which will also save it.
/** @var \Drupal\message_notify\MessageNotifier $message_notifier */
$message_notifier = \Drupal::service('message_notify.sender');
$message_notifier->send($message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment