- Issue created by @Bao Truong
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).
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.
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.
Downport
Code