You are here

public function UserEmailVerification::initEmailMessage in User email verification 8

Fill email message with data. A hook_mail() handler.

Parameters

string $key: A key to identify the email sent.

array $message: A message array to be filled in.

array $params: An array of message parameters.

Overrides UserEmailVerificationInterface::initEmailMessage

File

src/UserEmailVerification.php, line 535

Class

UserEmailVerification
User email verification helper service.

Namespace

Drupal\user_email_verification

Code

public function initEmailMessage($key, array &$message, array $params) {

  /** @var \Drupal\user\UserInterface $user */
  $user = $params['user'];
  switch ($key) {
    case 'verify':
      $message['subject'] = $this->token
        ->replace((string) $this
        ->getMailSubject(), [
        'user' => $user,
      ]);
      $message['body'][] = $this->token
        ->replace((string) $this
        ->getMailBody(), [
        'user' => $user,
      ]);
      break;
    case 'verify_blocked':
      $message['subject'] = $this
        ->t('A blocked account verified Email.');
      $message['body'][] = $this
        ->t('Blocked account with name: @name, ID: @id verified own Email: @email', [
        '@id' => $user
          ->id(),
        '@name' => $user
          ->getAccountName(),
        '@email' => $user
          ->getEmail(),
      ]);
      $message['body'][] = Url::fromRoute('entity.user.edit_form', [
        'user' => $user
          ->id(),
      ], [
        'absolute' => TRUE,
      ])
        ->toString();
      $message['body'][] = $this
        ->t('If the account is not blocked for other reason, please unblock the account.');
      break;
    case 'verify_extended':
      $message['subject'] = $this->token
        ->replace((string) $this
        ->getExtendedMailSubject(), [
        'user' => $user,
      ]);
      $message['body'][] = $this->token
        ->replace((string) $this
        ->getExtendedMailBody(), [
        'user' => $user,
      ]);
      break;
  }
}