class Email in Message Notify 8
Email notifier.
Plugin annotation
@Notifier(
id = "email",
title = @Translation("Email"),
description = @Translation("Send messages via email"),
viewModes = {
"mail_subject",
"mail_body"
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\message_notify\Plugin\Notifier\MessageNotifierBase implements MessageNotifierInterface
- class \Drupal\message_notify\Plugin\Notifier\Email
- class \Drupal\message_notify\Plugin\Notifier\MessageNotifierBase implements MessageNotifierInterface
Expanded class hierarchy of Email
1 file declares its use of Email
- EmailTest.php in tests/
src/ Unit/ Plugin/ Notifier/ EmailTest.php
File
- src/
Plugin/ Notifier/ Email.php, line 26
Namespace
Drupal\message_notify\Plugin\NotifierView source
class Email extends MessageNotifierBase {
/**
* The mail manager service.
*
* @var \Drupal\Core\Mail\MailManagerInterface
*/
protected $mailManager;
/**
* Constructs the email notifier plugin.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Logger\LoggerChannelInterface $logger
* The message_notify logger channel.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\Core\Render\RendererInterface $render
* The rendering service.
* @param \Drupal\message\MessageInterface $message
* (optional) The message entity. This is required when sending or
* delivering a notification. If not passed to the constructor, use
* ::setMessage().
* @param \Drupal\Core\Mail\MailManagerInterface $mail_manager
* The mail manager service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerChannelInterface $logger, EntityTypeManagerInterface $entity_type_manager, RendererInterface $render, MessageInterface $message = NULL, MailManagerInterface $mail_manager) {
// Set configuration defaults.
$configuration += [
'mail' => FALSE,
'language override' => FALSE,
'from' => FALSE,
];
parent::__construct($configuration, $plugin_id, $plugin_definition, $logger, $entity_type_manager, $render, $message);
$this->mailManager = $mail_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MessageInterface $message = NULL) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('logger.channel.message_notify'), $container
->get('entity_type.manager'), $container
->get('renderer'), $message, $container
->get('plugin.manager.mail'));
}
/**
* {@inheritdoc}
*/
public function deliver(array $output = []) {
/** @var \Drupal\user\UserInterface $account */
$account = $this->message
->getOwner();
if (!$this->configuration['mail'] && !$account
->id()) {
// The message has no owner and no mail was passed. This will cause an
// exception, we just make sure it's a clear one.
throw new MessageNotifyException('It is not possible to send a Message to an anonymous owner. You may set an owner using ::setOwner() or pass a "mail" to the $options array.');
}
$mail = $this->configuration['mail'] ?: $account
->getEmail();
$from = $this->configuration['from'] ?: NULL;
if (!$this->configuration['language override']) {
$language = $account
->getPreferredLangcode();
}
else {
$language = $this->message
->language()
->getId();
}
// The subject in an email can't be with HTML, so strip it.
$output['mail_subject'] = trim(strip_tags($output['mail_subject']));
// Pass the message entity along to hook_drupal_mail().
$output['message_entity'] = $this->message;
$result = $this->mailManager
->mail('message_notify', $this->message
->getTemplate()
->id(), $mail, $language, $output, $from);
return $result['result'];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Email:: |
protected | property | The mail manager service. | |
Email:: |
public static | function |
Creates an instance of the plugin. Overrides MessageNotifierBase:: |
|
Email:: |
public | function |
Deliver a message via the required transport method. Overrides MessageNotifierInterface:: |
|
Email:: |
public | function |
Constructs the email notifier plugin. Overrides MessageNotifierBase:: |
|
MessageNotifierBase:: |
protected | property | The entity type manager service. | |
MessageNotifierBase:: |
protected | property | The logger channel. | |
MessageNotifierBase:: |
protected | property | The message entity. | |
MessageNotifierBase:: |
protected | property | The rendering service. | |
MessageNotifierBase:: |
public | function |
Determine if user can access notifier. Overrides MessageNotifierInterface:: |
|
MessageNotifierBase:: |
public | function |
Save the rendered messages if needed.
Invoke watchdog error on failure. Overrides MessageNotifierInterface:: |
|
MessageNotifierBase:: |
public | function |
Entry point to send and process a message. Overrides MessageNotifierInterface:: |
|
MessageNotifierBase:: |
public | function |
Set the message object for the notifier. Overrides MessageNotifierInterface:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. |