- π¦πΊAustralia thomwilhelm Sydney
I came across this same error while testing the PHP 8.1 upgrade, but it was actually caused by a custom module I wrote that reformatted the users display name by implementing hook_user_format_name_alter(). The problem was with the custom logic I wrote, the return value for the Anonymous user was returning NULL, triggering this error.
To fix I needed to add a case for the anonymous user to not reformat their username:
function my_module_user_format_name_alter(&$name, AccountInterface $account) { if ($account->isAnonymous()) { return; } // Existing custom logic. }
- Status changed to Postponed: needs info
over 1 year ago 5:51am 18 April 2023 - π¦πΊAustralia thomwilhelm Sydney
If this is to be re-opened, I feel we need steps to replicate to a vanilla Drupal install, as likely the issue is in custom code as previously mentioned.
- πΈπͺSweden hansson192
I got this exact error whilst trying to update Drupal to 9.5.9 and running phpUnit on our custom modules in a custom profile. Your patch did indeed solve our issues but whilst looking into the error I noticed that the user entity's getDisplayName defaults to user.settings value for anonymous, and said file was missing for us because of some changes that had been made to our testing process.
public function getDisplayName() { $name = $this->getAccountName() ?: \Drupal::config('user.settings')->get('anonymous'); \Drupal::moduleHandler()->alter('user_format_name', $name, $this); return $name; }
So by making sure that user.settings.yml with the key anonymous and a value existed and were accessible the errors disappeared.
- π¬π§United Kingdom jkdaza
#17 π Passing null to mb_strlen is deprecated in template_preprocess_username Postponed: needs info really helped, thanks!
We also experienced this issue and we tracked it down to one of the custom modules implementing `hook_user_format_name_alter` was returning NULL for anonymous users.
I changed this:
function MYMODULE_user_format_name_alter(&$name, AccountInterface $account) { $name = $account->getEmail(); }
into this:
function MYMODULE_user_format_name_alter(&$name, AccountInterface $account) { if ($account->isAnonymous()) { return; } $name = $account->getEmail(); }
- Status changed to Closed: works as designed
3 months ago 10:57am 27 September 2024 - π³πΏNew Zealand quietone
There are not steps to reproduce this from Drupal core and all the comments where it was resolved say it was due to a custom module. Steps to reproduce this on Drupal Core were asked for 2 years ago and haven't been supplied. Since that is needed to keep this open, I am closing this issue.
If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue β (starting from "Install Drupal core").
Thanks!