Call to undefined method Drupal\user\Entity\User::getUsername()

Created on 26 April 2023, over 1 year ago

Problem/Motivation

Drupal core version 9.5.7

After applying the patch from https://www.drupal.org/node/3275084 β†’ that allows us to add akismet protect to form display modes, I ran into the following error when attempting to create a node using a custom form display mode that I had configured akismet protection for.

The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Drupal\user\Entity\User::getUsername() in Drupal\akismet\Controller\FormController::extractAkismetValues() (line 237 of modules/contrib/akismet/src/Controller/FormController.php).

Steps to reproduce

Create a custom form display mode
Add akismet protection for that form display mode in the config
Submit that form as a regular user (not one with special akismet bypass permission) and you will see the error.

Proposed resolution

We will just need to replace the deprecated function getUsername() on line 237 in modules/contrib/akismet/src/Controller/FormController.php with the following function getDisplayName().

So this piece of code on line 237 in modules/contrib/akismet/src/Controller/FormController.php

    $author_username = $account->getUsername();

Can look like this

    $author_username = $account->getDisplayName();

A patch to be uploaded.

πŸ› Bug report
Status

Downport

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Bao Truong

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

Comments & Activities

Production build 0.71.5 2024