You are here

function _user_registrationpassword_mail_notify in User registration password 8

Conditionally create and send a notification email when a certain operation happens on the given user account.

Parameters

$op: The operation being performed on the account. Possible values: confirmation_with_pass / confirmation_admin_created.

\Drupal\Core\Session\AccountInterface $account: The user object of the account being notified. Must contain at least the fields 'uid', 'name', and 'mail'.

string $langcode: (optional) Language code to use for the notification, overriding account language.

Return value

array An array containing various information about the message. See \Drupal\Core\Mail\MailManagerInterface::mail() for details.

See also

user_registrationpassword_mail_tokens()

3 calls to _user_registrationpassword_mail_notify()
UserRegistrationPasswordMailNotifyTest::testUserRegistrationMailsSent in tests/src/Kernel/UserRegistrationPasswordMailNotifyTest.php
Tests mails are sent.
user_registrationpassword_form_user_register_submit in ./user_registrationpassword.module
Implements submission handler for the user registration form.
_user_registrationpassword_user_pass_submit in ./user_registrationpassword.module
Implements submit function.

File

./user_registrationpassword.module, line 554
Enables password creation on registration form.

Code

function _user_registrationpassword_mail_notify($op, AccountInterface $account, $langcode = NULL) {
  if (\Drupal::config('user_registrationpassword.settings')
    ->get('notify.' . $op)) {
    $params['account'] = $account;
    $langcode = $langcode ? $langcode : $account
      ->getPreferredLangcode();

    // Get the custom site notification email to use as the from email address
    // if it has been set.
    $site_mail = \Drupal::config('system.site')
      ->get('mail_notification');

    // If the custom site notification email has not been set, we use the site
    // default for this.
    if (empty($site_mail)) {
      $site_mail = \Drupal::config('system.site')
        ->get('mail');
    }
    if (empty($site_mail)) {
      $site_mail = ini_get('sendmail_from');
    }

    // Notify the user.
    $mail = \Drupal::service('plugin.manager.mail')
      ->mail('user_registrationpassword', $op, $account
      ->getEmail(), $langcode, $params, $site_mail);
    return empty($mail) ? NULL : $mail['result'];
  }
}