From 835b68ebfb15c97b30cc5c34aa8a51030a690492 Mon Sep 17 00:00:00 2001 From: Matthew Slater <matslats@fastmail.com> Date: Sun, 10 Dec 2023 13:55:09 +1100 Subject: [PATCH] drupal 10 compatibility fix --- alt_login.make.yml | 6 ------ alt_login.module | 2 +- src/Plugin/AltLoginMethod/AddressName.php | 19 ++++++++++++------- src/Settings.php | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) delete mode 100644 alt_login.make.yml diff --git a/alt_login.make.yml b/alt_login.make.yml deleted file mode 100644 index 6cb13d2..0000000 --- a/alt_login.make.yml +++ /dev/null @@ -1,6 +0,0 @@ -core: "8.x" -api: 2 -projects: - token: - type: "module" - version: "1.5" diff --git a/alt_login.module b/alt_login.module index 2ee8490..adac79a 100644 --- a/alt_login.module +++ b/alt_login.module @@ -84,7 +84,7 @@ function alt_login_form_alter(&$form, $form_state, $form_id) { if (empty($user_aliases['username'])) { $namefield['#access'] = FALSE; if ($user->isNew()) { - $namefield['#value'] = user_password(8); + $namefield['#value'] = \Drupal::service('password_generator')->generate(8); } elseif (count($user_aliases) == 1) { $labels = \Drupal::service('alt_login.method_manager')->getActiveLabels(); diff --git a/src/Plugin/AltLoginMethod/AddressName.php b/src/Plugin/AltLoginMethod/AddressName.php index 951c2b9..937840f 100644 --- a/src/Plugin/AltLoginMethod/AddressName.php +++ b/src/Plugin/AltLoginMethod/AddressName.php @@ -19,7 +19,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * * @AltLoginMethod( * id = "address_name", - * label = @Translation("Full name"), + * label = @Translation("Address firstname + lastname"), * description = @Translation("The given name and family name from the address field. Warning, duplicate names could lead to login and other confusions.") * ) */ @@ -48,6 +48,11 @@ class AddressName implements AltLoginMethodInterface, ContainerFactoryPluginInte */ private $entityTypeManager; + /** + * @var MessengerInterface + */ + private $messenger; + /** * @param EntityFieldManagerInterface $entity_field_manager * @param Connection $database @@ -137,15 +142,15 @@ class AddressName implements AltLoginMethodInterface, ContainerFactoryPluginInte return $this->fieldName; } + /** + * {@inheritdoc} + */ private function getUids($alias) { $fname = $this->fieldName(); - $table = 'user__'.$fname; - $query = $this->database->select($table, 'u') + $query = $this->database + ->select('user__'.$fname, 'u') ->fields('u', ['entity_id']) - ->where( - "CONCAT_WS(:space, {$fname}_given_name, {$fname}_family_name) ='".$alias."'", - [':space' => ' '] - ); + ->where("CONCAT_WS(' ', {$fname}_given_name, {$fname}_family_name) = '$alias'"); // Hopefully the database field isn't case sensitive. return $query->execute()->fetchCol(); } diff --git a/src/Settings.php b/src/Settings.php index 752f061..248bbfe 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -25,7 +25,7 @@ class Settings extends ConfigFormBase { $config = $this->config('alt_login.settings'); $form['aliases'] = [ '#title' => $this->t('Allow login with'), - '#description' => $this->t('Unchecking the username prevents its use for logging in.'), + '#description' => $this->t('Unchecking the username prevents its use for logging in, and hides the username field from the user form.'), '#type' => 'checkboxes', '#options' => \Drupal::service('alt_login.method_manager')->getOptions(), '#default_value' => (array)$config->get('aliases'), -- GitLab