You are here

public function Email::getActivationMail in Search API Saved Searches 8

Prepares a message for activating a new saved search.

Parameters

array|\ArrayAccess $message: An array to be filled in. Elements in this array include:

  • id: An ID to identify the mail sent. Look at module source code or MailManagerInterface->mail() for possible id values.
  • to: The address or addresses the message will be sent to. The formatting of this string must comply with RFC 2822.
  • subject: Subject of the email to be sent. This must not contain any newline characters, or the mail may not be sent properly. MailManagerInterface->mail() sets this to an empty string when the hook is invoked.
  • body: An array of lines containing the message to be sent. Drupal will format the correct line endings for you. MailManagerInterface->mail() sets this to an empty array when the hook is invoked. The array may contain either strings or objects implementing \Drupal\Component\Render\MarkupInterface.
  • from: The address the message will be marked as being from, which is set by MailManagerInterface->mail() to either a custom address or the site-wide default email address when the hook is invoked.
  • headers: Associative array containing mail headers, such as From, Sender, MIME-Version, Content-Type, etc. MailManagerInterface->mail() pre-fills several headers in this array.

array|\ArrayAccess $params: An associative array with the following keys:

  • search: The saved search entity which can be activated.

See also

hook_mail()

search_api_saved_searches_mail()

File

src/Plugin/search_api_saved_searches/notification/Email.php, line 490

Class

Email
Provides e-mails as a notification mechanism.

Namespace

Drupal\search_api_saved_searches\Plugin\search_api_saved_searches\notification

Code

public function getActivationMail(&$message, $params) {

  /** @var \Drupal\search_api_saved_searches\SavedSearchInterface $search */
  $search = $params['search'];
  $account = $search
    ->getOwner();
  $data = [
    'search_api_saved_search' => $search,
    'user' => $account,
  ];
  $options['langcode'] = $this
    ->getPreferredLangcode($search);
  $options['clear'] = TRUE;
  $subject = $this->configuration['activate']['title'];
  $subject = $this
    ->getTokenService()
    ->replace($subject, $data, $options);
  $body = $this->configuration['activate']['body'];

  // Token only works with HTML.
  $body = Html::escape($body);
  $body = $this
    ->getTokenService()
    ->replace($body, $data, $options);
  $message['subject'] = $subject;
  $message['body'][] = Html::decodeEntities($body);
}