Change record status: 
Project: 
Introduced in branch: 
11.5.x
Introduced in version: 
11.5.0
Description: 

The function _user_mail_notify() is deprecated. It is replaced by a service, \Drupal\user\NotificationHandler'.

It was theoretically possible to invoke _user_mail_notify() with a custom value for the $op parameter. This functionality is not supported on the user mail handler.

The NotificationHandler is marked as @internal. Methods on this class are not covered by the BC policy.

Mapping of $op parameters to methods

$op parameter to _user_mail_notify() method on NotificationHandler
register_admin_created sendRegisterAdminCreated()
register_no_approval_required sendRegisterNoApprovalRequired()
register_pending_approval sendRegisterPendingApproval()
password_reset sendPasswordReset()
status_activated sendStatusActivated()
status_blocked sendStatusBlocked()
cancel_confirm sendCancelConfirm()
status_canceled sendStatusCanceled()

Example

Before

// Send account canceled notification if option was checked.
if (!empty($edit['user_cancel_notify'])) {
  _user_mail_notify('status_canceled', $account);
}
$account->delete();
\Drupal::messenger()->addStatus(t('Account %name has been deleted.', ['%name' => $accotDisplayName()]));

After

// Send account canceled notification if option was checked.
if (!empty($edit['user_cancel_notify'])) {
  \Drupal::service(NotificationHandler::class)->sendStatusCanceled($account);
}
$account->delete();
\Drupal::messenger()->addStatus(t('Account %name has been deleted.', ['%name' => $accotDisplayName()]));

Further work being done in #3578758: Investigate calls to _user_mail_notify() to identify missing API surface

Impacts: 
Module developers