From 73b7b1b2f2ed73f46e89ecb4b759a8cfaedc4199 Mon Sep 17 00:00:00 2001 From: Matthew Slater <matslats@fastmail.com> Date: Mon, 1 Aug 2022 13:40:47 +0200 Subject: [PATCH] fixed problem getting name for new accounts. --- alt_login.module | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/alt_login.module b/alt_login.module index 32b1c86..ceaca7c 100644 --- a/alt_login.module +++ b/alt_login.module @@ -26,7 +26,7 @@ function alt_login_help($route_name, $route_match) { * @note there's no easy way to dedupe accounts' display names. */ function alt_login_user_format_name_alter(&$name, AccountInterface $account) { - if ($account->isAnonymous()) { + if ($account->isAnonymous()) { // includes accounts tha // This will be the configured 'anonymous' value return; } @@ -34,14 +34,14 @@ function alt_login_user_format_name_alter(&$name, AccountInterface $account) { $uid = $account->id(); if (!isset($names[$uid])) { // Anonymous users - if (\Drupal::currentUser()->isAnonymous()) { + if (\Drupal::currentUser()->isAnonymous() and !$account->isNew()) { $anon = \Drupal::config('alt_login.settings')->get('display_anon'); $names[$uid] = \Drupal::token() ->replace($anon, ['user' => $account], ['clear' => true]); } // Do the replacement if the module is configured. elseif ($template = \Drupal::config('alt_login.settings')->get('display')) { - $user = User::load($uid); + $user = $account instanceOf UserInterface ? $account : User::load($uid); $names[$uid] = \Drupal::token()->replace( $template, ['user' => $user], @@ -79,6 +79,7 @@ function alt_login_form_alter(&$form, $form_state, $form_id) { $user = $form_state->getFormObject()->getEntity(); $aliases = alt_login_get_aliases($user); $namefield = &$form['account']['name']; + dump($aliases); if (empty($aliases['username'])) { if ($user->isNew()) { $namefield['#access'] = FALSE; -- GitLab