class InviteByEmail in Invite 8
Class for Invite by Email.
Plugin annotation
@Plugin(
id="invite_by_email",
label = @Translation("Invite By Email")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\invite_by_email\Plugin\Invite\InviteByEmail implements ContainerFactoryPluginInterface, InvitePluginInterface uses StringTranslationTrait
Expanded class hierarchy of InviteByEmail
1 file declares its use of InviteByEmail
- InviteResendForm.php in src/
Form/ InviteResendForm.php
File
- modules/
invite_by_email/ src/ Plugin/ Invite/ InviteByEmail.php, line 21
Namespace
Drupal\invite_by_email\Plugin\InviteView source
class InviteByEmail extends PluginBase implements InvitePluginInterface, ContainerFactoryPluginInterface {
use StringTranslationTrait;
/**
* The Messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* Getter for the messenger service.
*
* @return \Drupal\Core\Messenger\MessengerInterface
*/
public function getMessenger() {
return $this->messenger;
}
/**
* Constructs invite_by_email plugin.
*
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MessengerInterface $messenger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->messenger = $messenger;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('messenger'));
}
/**
* {@inheritdoc}
*/
public function send($invite) {
/*
* @var $token \Drupal\token\Token
* @var $mail \Drupal\Core\Mail\MailManager
*/
$bubbleable_metadata = new BubbleableMetadata();
$token = \Drupal::service('token');
$mail = \Drupal::service('plugin.manager.mail');
$mail_key = $invite
->get('type')->value;
// Prepare message.
$message = $mail
->mail('invite_by_email', $mail_key, $invite
->get('field_invite_email_address')->value, $invite->activeLangcode, [], $invite
->getOwner()
->getEmail(), FALSE);
// If HTML email.
if (unserialize(\Drupal::config('invite.invite_type.' . $invite
->get('type')->value)
->get('data'))['html_email']) {
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8;';
}
$message['subject'] = $token
->replace($invite
->get('field_invite_email_subject')->value, [
'invite' => $invite,
], [], $bubbleable_metadata);
$body = [
'#theme' => 'invite_by_email',
'#body' => $token
->replace($invite
->get('field_invite_email_body')->value, [
'invite' => $invite,
], [], $bubbleable_metadata),
];
$message['body'] = \Drupal::service('renderer')
->render($body)
->__toString();
// Send.
$system = $mail
->getInstance([
'module' => 'invite_by_email',
'key' => $mail_key,
]);
$result = $system
->mail($message);
if ($result) {
$this
->getMessenger()
->addStatus($this
->t('Invitation has been sent.'));
$mail_user = $message['to'];
\Drupal::logger('invite')
->notice('Invitation has been sent for: @mail_user.', [
'@mail_user' => $mail_user,
]);
}
else {
$this
->getMessenger()
->addStatus($this
->t('Failed to send a message.'), 'error');
\Drupal::logger('invite')
->error('Failed to send a message.');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InviteByEmail:: |
protected | property | The Messenger service. | |
InviteByEmail:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
InviteByEmail:: |
public | function | Getter for the messenger service. | |
InviteByEmail:: |
public | function |
Plugin send method. Overrides InvitePluginInterface:: |
|
InviteByEmail:: |
public | function |
Constructs invite_by_email plugin. Overrides PluginBase:: |
|
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. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |