Created
September 25, 2016 14:22
-
-
Save amitaibu/cb1933a663fc902271f10bc8617dbbd1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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