Drupal 8 ServiceNotFoundException "password_generator"

Created on 27 April 2024, 7 months ago
Updated 16 July 2024, 4 months ago

Drupal:8.9.20 PHP:7.3

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "password_generator". in Drupal\Component\DependencyInjection\Container->get() (line 153 of /var/www/core/lib/Drupal/Component/DependencyInjection/Container.php).

  1. https://api.drupal.org/api/drupal/core!modules!user!user.module/function...
  2. https://api.drupal.org/api/drupal/core%21modules%21user%21user.module/fu... (in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Password\PasswordGeneratorInterface::generate() instead.)

Solution: auto_username.module

function auto_username_form_user_register_form_alter(&$form, &$form_state, $form_id) {
  $form['account']['name']['#type'] = 'hidden';
/*WTpatchOwn: D8.9 non-existent service "password_generator"*/
  //$form['account']['name']['#value'] = \Drupal::service('password_generator')->generate();
  $form['account']['name']['#value'] = (!empty(\Drupal::hasService('password_generator'))) ? \Drupal::service('password_generator')->generate() : user_password();
/*<<<*/
}
πŸ› Bug report
Status

Closed: outdated

Version

1.5

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024