You are here

protected function Settings::copyCoreToCourierEmail in Courier 2.x

Same name and namespace in other branches
  1. 8 courier_system/src/Form/Settings.php \Drupal\courier_system\Form\Settings::copyCoreToCourierEmail()

Copy email contents from Drupal to Courier email templates.

Template collection and email template must be created prior to calling.

Parameters

\Drupal\courier\TemplateCollectionInterface $template_collection: A template collection entity.

string $mail_id: A mail ID as defined in $this->getSystemMails().

2 calls to Settings::copyCoreToCourierEmail()
Settings::submitCreateMessages in courier_system/src/Form/Settings.php
Submit handler for create messages table.
Settings::submitForm in courier_system/src/Form/Settings.php
Form submission handler.

File

courier_system/src/Form/Settings.php, line 330

Class

Settings
Configure Courier System settings.

Namespace

Drupal\courier_system\Form

Code

protected function copyCoreToCourierEmail(TemplateCollectionInterface &$template_collection, $mail_id) {

  // Only user is supported at this time.
  $key = substr($mail_id, strlen('user_'));
  $user_mails = $this
    ->config('user.mail');
  $mail = $user_mails
    ->get($key);

  /** @var \Drupal\courier\Entity\Email $courier_email */
  if ($courier_email = $template_collection
    ->getTemplate('courier_email')) {
    foreach ($mail as &$value) {
      $value = nl2br($value);
      $value = str_replace('[user:name]', '[identity:label]', $value);
    }
    $courier_email
      ->setSubject($mail['subject'])
      ->setBody($mail['body'])
      ->save();
    $template_collection
      ->setTemplate($courier_email);
  }
}