Problem/Motivation
After updating Drupal core to 11.4, every page that renders an image field
using the "Image Field Tokens" formatter fails with a WSOD / HTTP 500:
PHP Fatal error: Type of
Drupal\imagefield_tokens\Plugin\Field\FieldFormatter\ImageFieldTokensFormatter::$currentUser
must be Drupal\Core\Session\AccountInterface (as in class
Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter) in
web/modules/contrib/imagefield_tokens/src/Plugin/Field/FieldFormatter/ImageFieldTokensFormatter.php
on line 34
`ImageFieldTokensFormatter` re-declares two properties that are inherited
from core's `ImageFormatter`:
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* The image style entity storage.
*
* @var \Drupal\image\ImageStyleStorageInterface
*/
protected $imageStyleStorage;
Drupal 11.4 added native type declarations to these properties in core's
`ImageFormatter`. Since PHP property types are invariant, the untyped
re-declarations in the child class now cause a fatal error as soon as the
class is loaded. The fatal is currently reported for `$currentUser`; once
that is fixed, `$imageStyleStorage` will trigger the same error.
Steps to reproduce
- Install Drupal core 11.4 with imagefield_tokens 3.2.0
- Configure an image field on any content type to use the
"Image Field Tokens" formatter on Manage display. - Visit a page that renders this field.
- HTTP 500 with the fatal error above.
Proposed resolution
Remove both redundant property declarations from
`ImageFieldTokensFormatter`. They are inherited from the parent class and
are already assigned via `parent::__construct()`, so no other changes are
required.
Because the properties are removed rather than typed, the fix remains
backwards compatible with Drupal 11.3 and 10.x.
Remaining tasks
- Review MR.
- Commit and tag a new release.
Issue fork imagefield_tokens-3607919
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
jstollerWorks as advertised, and much appreciated.
Comment #8
decipheredThanks @gemisky for the report and initial fix, and @jstoller for testing.
Committed and expanded on the fix with a broader code modernisation pass for full Drupal 11.4 compatibility:
$currentUserand$imageStyleStorageproperty declarations fromImageFieldTokensFormatterColorboxFormatter,ImageFieldTokensCropWidget, andImageFieldTokensWigdet