The Anonymous Token module is incompatible with Drupal 11.2 due to a PHP fatal error caused by improper property type inheritance in the AnonymousCsrfAccessCheck class.
Install Drupal 11.2 with PHP 8.3
Install and enable the Anonymous Token module
Clear cache using drush cr or through the admin interface
Observe the following fatal error:
PHP Fatal error: Type of Drupal\anonymous_token\Access\AnonymousCsrfAccessCheck::$csrfToken must be Drupal\Core\Access\CsrfTokenGenerator (as in class Drupal\Core\Access\CsrfAccessCheck) in /var/www/html/web/modules/contrib/anonymous_token/src/Access/AnonymousCsrfAccessCheck.php on line 12
Root Cause: The AnonymousCsrfAccessCheck class extends CsrfAccessCheck but attempts to redeclare the inherited $csrfToken property with a different type (AnonymousCsrfTokenGenerator instead of CsrfTokenGenerator). This violates PHP's property inheritance rules, which became stricter in PHP 8.3.
Remove the property redeclaration from AnonymousCsrfAccessCheck class - the property is already inherited from the parent class
Ensure AnonymousCsrfTokenGenerator extends CsrfTokenGenerator to maintain type compatibility
Update the constructor to properly inject the anonymous token generator while respecting the parent class's property typing
Code changes needed:
In src/Access/AnonymousCsrfAccessCheck.php:
Remove the protected $csrfToken property declaration
Keep only the constructor that assigns the injected service to the inherited property
In src/Access/AnonymousCsrfTokenGenerator.php:
Ensure the class extends Drupal\Core\Access\CsrfTokenGenerator
Override necessary methods to provide anonymous user functionality
Needs review
3.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
No activities found.