Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Marco Matta
Added: Oct 8, 2021 2:10 PM
Modified: Oct 8, 2021 3:07 PM
Views: 269
Tags: drupal
  1. \Drupal\user\Entity\User::create([
  2.         'name' => $this->email,
  3.         'mail' => $this->email,
  4.         'pass' => \Drupal::service('password_generator')->generate()
  5. ])->save();
  6.  
  7. $langcode =  \Drupal::languageManager()->getCurrentLanguage()->getId();
  8. $users = \Drupal::entityTypeManager()->getStorage('user')->loadByProperties(array('mail' => $this->email));
  9. if (empty($users)) {
  10.         $users = \Drupal::entityTypeManager()->getStorage('user')->loadByProperties(array('name' => $this->email));
  11. }
  12. // Reset the password and send forgotten password email to the user
  13. $account = reset($users);
  14. $mail = _user_mail_notify('password_reset', $account, $langcode);
  15.