I want to send the "admin (user awaiting approval)" email after creating an account in the user_insert hook
I don't know what function is used. I did find _user_mail_notify
which works well but only sends emails to registered users (and not to admins). Moreover, we see that _user_mail_notify
has 8 possible parameters which correspond to messages sent to users and not to admins (in the UI, there are 9 possibles messages).
I'm looking for a function like _admin_mail_notify
or _administrator_mail_notify
I know _admin_mail_notify
doesn't exist with that name but maybe that helps to be clearer.
Here is somethings that works to send a user an email :
function my_module_user_insert(\Drupal\user\UserInterface $user) {
// send email to new user
_user_mail_notify('register_pending_approval', $user);
// want to send user awaiting approval email, pseudo code
// _admin_mail_notify('lorem', $lorem);
}
EDIT 1
I had not specified it to simplify my question but I did not activate the option "Visitors, but administrator approval is required" because I have 2 types of registrants.
Users with an “A” role can register without email verification or admin approval. And another “B” role that must be approved by the admins. By default users can all register and in the hook_user_insert
I block the user with $user->block();
so I wanted to also send an email to the admins.
I found this code in user.module
which seems to be part of the solution:
if ($op == 'register_pending_approval') {
// If a user registered requiring admin approval, notify the admin, too.
// We use the site default language for this.
\Drupal::service('plugin.manager.mail')->mail('user', 'register_pending_approval_admin', $site_mail, \Drupal::languageManager()->getDefaultLanguage()->getId(), $params);
}
\Drupal::service('plugin.manager.mail')->mail('user', 'register_pending_approval_admin', $site_mail, \Drupal::languageManager()->getDefaultLanguage()->getId(), $params);
into yourhook_user_insert
code.