public function MailhandlerNode::invoke in Mailhandler 8
File
- src/
Plugin/ inmail/ Handler/ MailhandlerNode.php, line 77
Class
- MailhandlerNode
- Message handler that creates a node from a mail message.
Namespace
Drupal\mailhandler\Plugin\inmail\HandlerCode
public function invoke(MimeMessageInterface $message, ProcessorResultInterface $processor_result) {
try {
$result = $processor_result
->getAnalyzerResult();
if (!$result
->hasContext('entity_type') || $result
->getContext('entity_type')
->getContextValue()['entity_type'] != 'node') {
// Do not run this handler in case
// the identified entity type is not node.
return;
}
// Authenticate a user.
$this
->authenticateUser($result);
// Create a node.
$node = $this
->createNode($message, $result);
\Drupal::logger('mailhandler')
->log(RfcLogLevel::NOTICE, "\"{$node->label()}\" has been created by \"{$result->getAccount()->getDisplayName()}\".");
} catch (\Exception $e) {
// Log error in case verification, authentication or authorization fails.
\Drupal::logger('mailhandler')
->log(RfcLogLevel::WARNING, $e
->getMessage());
}
}