class SendEmailAction in CRM Core 8
Same name and namespace in other branches
- 8.3 modules/crm_core_contact/src/Plugin/Action/SendEmailAction.php \Drupal\crm_core_contact\Plugin\Action\SendEmailAction
- 8.2 modules/crm_core_contact/src/Plugin/Action/SendEmailAction.php \Drupal\crm_core_contact\Plugin\Action\SendEmailAction
Sends e-mail to contacts.
Plugin annotation
@Action(
id = "send_email_action",
label = @Translation("Send an e-mail to contacts"),
type = "crm_core_contact"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Action\ActionBase implements ActionInterface
- class \Drupal\Core\Action\ConfigurableActionBase implements ConfigurableInterface, ConfigurablePluginInterface, DependentPluginInterface, PluginFormInterface
- class \Drupal\crm_core_contact\Plugin\Action\SendEmailAction implements ContainerFactoryPluginInterface
- class \Drupal\Core\Action\ConfigurableActionBase implements ConfigurableInterface, ConfigurablePluginInterface, DependentPluginInterface, PluginFormInterface
- class \Drupal\Core\Action\ActionBase implements ActionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of SendEmailAction
File
- modules/
crm_core_contact/ src/ Plugin/ Action/ SendEmailAction.php, line 24
Namespace
Drupal\crm_core_contact\Plugin\ActionView source
class SendEmailAction extends ConfigurableActionBase implements ContainerFactoryPluginInterface {
/**
* The token service.
*
* @var \Drupal\Core\Utility\Token
*/
protected $token;
/**
* The mail manager.
*
* @var \Drupal\Core\Mail\MailManagerInterface
*/
protected $mailManager;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs a EmailAction object.
*
* @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\Utility\Token $token
* The token service.
* @param \Drupal\Core\Mail\MailManagerInterface $mail_manager
* The mail manager.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Token $token, MailManagerInterface $mail_manager, LanguageManagerInterface $language_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->token = $token;
$this->mailManager = $mail_manager;
$this->languageManager = $language_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('token'), $container
->get('plugin.manager.mail'), $container
->get('language_manager'));
}
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
return $return_as_object ? AccessResult::allowed() : AccessResult::allowed()
->isAllowed();
}
/**
* {@inheritdoc}
*/
public function executeMultiple(array $objects) {
$subject = isset($this->configuration['subject']) ? $this->configuration['subject'] : '';
$message = isset($this->configuration['message']) ? $this->configuration['message'] : '';
foreach ($objects as $contact) {
// Token replacement preparations.
$data = [
'crm_core_contact' => $contact,
];
$options = [
// Remove tokens that could not be found.
'clear' => TRUE,
];
$subject = $this->token
->replace($subject, $data, $options);
$message = $this->token
->replace($message, $data, $options);
$email = $contact
->getPrimaryEmail()->value;
$params = [
'subject' => $subject,
'message' => $message,
];
$langcode = $this->languageManager
->getCurrentLanguage()
->getId();
$this->mailManager
->mail('crm_core_contact', 'send_email', $email, $langcode, $params);
}
}
/**
* {@inheritdoc}
*/
public function execute($object = NULL) {
$this
->executeMultiple([
$object,
]);
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = [];
$form['subject'] = [
'#type' => 'textfield',
'#title' => $this
->t('Subject'),
'#description' => $this
->t('The subject of the message.'),
'#default_value' => $form_state
->getValue('subject', ''),
];
$form['message'] = [
'#type' => 'textarea',
'#title' => $this
->t('Message'),
'#description' => $this
->t('The message that should be sent.'),
'#default_value' => $form_state
->getValue('message', ''),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['subject'] = $form_state
->getValue('subject');
$this->configuration['message'] = $form_state
->getValue('message');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigurableActionBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
1 |
ConfigurableActionBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
8 |
ConfigurableActionBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ConfigurableActionBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ConfigurableActionBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
2 |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
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. | |
SendEmailAction:: |
protected | property | The language manager. | |
SendEmailAction:: |
protected | property | The mail manager. | |
SendEmailAction:: |
protected | property | The token service. | |
SendEmailAction:: |
public | function |
Checks object access. Overrides ActionInterface:: |
|
SendEmailAction:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
SendEmailAction:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
SendEmailAction:: |
public | function |
Executes the plugin. Overrides ExecutableInterface:: |
|
SendEmailAction:: |
public | function |
Executes the plugin for an array of objects. Overrides ActionBase:: |
|
SendEmailAction:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
SendEmailAction:: |
public | function |
Constructs a EmailAction object. Overrides ConfigurableActionBase:: |
|
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. |