You are here

public function SendEmailAction::executeMultiple in CRM Core 8

Same name and namespace in other branches
  1. 8.3 modules/crm_core_contact/src/Plugin/Action/SendEmailAction.php \Drupal\crm_core_contact\Plugin\Action\SendEmailAction::executeMultiple()
  2. 8.2 modules/crm_core_contact/src/Plugin/Action/SendEmailAction.php \Drupal\crm_core_contact\Plugin\Action\SendEmailAction::executeMultiple()

Executes the plugin for an array of objects.

Parameters

array $objects: An array of entities.

Overrides ActionBase::executeMultiple

1 call to SendEmailAction::executeMultiple()
SendEmailAction::execute in modules/crm_core_contact/src/Plugin/Action/SendEmailAction.php
Executes the plugin.

File

modules/crm_core_contact/src/Plugin/Action/SendEmailAction.php, line 91

Class

SendEmailAction
Sends e-mail to contacts.

Namespace

Drupal\crm_core_contact\Plugin\Action

Code

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);
  }
}