Skip to content

Drupal 11.4 compatibility fix - #1110

Merged
joecorall merged 3 commits into
Islandora:2.xfrom
joshdentremont:joshdentremont-patch-1
Jul 23, 2026
Merged

Drupal 11.4 compatibility fix#1110
joecorall merged 3 commits into
Islandora:2.xfrom
joshdentremont:joshdentremont-patch-1

Conversation

@joshdentremont

Copy link
Copy Markdown
Member

What does this Pull Request do?

After updating to Drupal 11.4.x my views that had images in them stopped working (eg. my search results with the thumbnails). It threw this error:

ArgumentCountError: Too few arguments to function Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter::__construct(), 10 passed in /var/www/drupal/web/modules/contrib/islandora/src/Plugin/Field/FieldFormatter/IslandoraImageFormatter.php on line 84 and exactly 11 expected in Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter->__construct() (line 32 of /var/www/drupal/web/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php).

This PR mostly comes from Claude, so I'm going to copy the relevant conversation here:

What happened. Drupal 11.4.0 rewrote ImageFormatter. The constructor moved to property promotion with typed properties (so $fileUrlGenerator is now protected FileUrlGeneratorInterface $fileUrlGenerator), and a new required argument, ImageDerivativeUtilities $imageDerivativeUtilities, was added — that's change record node/3567619. IslandoraImageFormatter extends ImageFormatter and calls parent::__construct() with the old ten-argument signature, so it now comes up one short. Nothing about your view is actually broken; the formatter plugin just can't be instantiated.
Drupal

That confirms it — pattern (b), and line 84 is the parent::__construct() call. Islandora's constructor takes twelve arguments and forwards ten to core, which now wants eleven.

The patch removes the constructor override entirely rather than adding the missing argument. The whole class of bug here is that Islandora is manually reassembling core's constructor call — so the durable fix is to stop doing that and let parent::create() build the instance, then set Islandora's two services on it afterward:

Nothing else in the class touched the constructor's dependencies directly — viewElements() only uses $this->utils and $this->mediaSourceService, both still populated. Four use statements became unused once the constructor went, so those are dropped too.
This also works unchanged on 11.3, which the add-the-argument approach doesn't, since ImageDerivativeUtilities doesn't exist there.

Let me build the clean version. There's one extra cleanup the earlier draft missed: once the constructor is gone, the IslandoraUtils and MediaSourceService imports are only referenced by fully-qualified name in the @var docblocks, so they become unused imports and PHPCS would flag them in Islandora's CI. I'll drop those too.

The whole change is: delete the __construct() override, and rewrite create() to delegate to parent::create() before setting Islandora's two services on the returned instance. Because both utils and mediaSourceService are already declared as class properties, setting them this way doesn't create dynamic properties, so there's no PHP 8.2 deprecation to worry about. I also dropped four imports that were only used by the old constructor, plus IslandoraUtils and MediaSourceService, which are now referenced only by fully-qualified name in the @var docblocks.

Why it satisfies your cross-version requirement: the class no longer references core's constructor signature anywhere. On 11.4, parent::create() supplies ImageDerivativeUtilities; on 10.x and 11.0–11.3 it doesn't. This subclass behaves identically either way, so the same file works against the whole supported range without a version check.

How should this be tested?

I tested on my site with version 11.4.4 and 11.3.13, and on a fresh site template install of 11.3.12 and everything seemed to work as intended.

I would recommend testing before and after updating Drupal to 11.4.x, as well as testing Drupal 11.4.4 without this patch to see that the search results breaks .

Documentation Status

N/A

Interested parties

@Islandora/committers

Refactor IslandoraImageFormatter constructor to use parent create method and set dependencies after instantiation.
Removed comments explaining the parent formatter instance creation.
@joecorall
joecorall merged commit 98be651 into Islandora:2.x Jul 23, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants