Problem/Motivation

ImageUrlFormatter (plugin ID: image_url) does not override calculateDependencies() or onDependencyRemoval(). This means that when a view display or entity view display uses the image_url formatter with a configured image style, the image style is not declared as a config dependency.

As a consequence:

  • Deleting the referenced image style is not blocked by Drupal's dependency system
  • No cascade update occurs (e.g., falling back to no style) when the image style is removed
  • Programmatic re-save of the entity view display via drush config:export silently drops the image style from the dependencies.config list, even though the formatter still references it in its settings

How it was discovered

During a config normalization pass (programmatic re-save of all config entities followed by config export), a core.entity_view_display for a block content type lost image.style.front_carousel from its dependencies.config section — despite the formatter explicitly referencing that image style in its settings.image_style key:

content:
  field_banner_hatterkep:
    type: image_url        # ← this formatter
    label: hidden
    settings:
      image_style: front_carousel   # ← references the image style

Manually re-saving the display through the admin UI (/admin/structure/block-content/manage/banner/display) confirmed the same result: the image style dependency is never computed.

Root cause

The inheritance chain is:

PluginSettingsBase (has generic calculateDependencies — returns empty)
  └─ ImageFormatterBase (no override)
       ├─ ImageFormatter (overrides calculateDependencies + onDependencyRemoval ✅)
       └─ ImageUrlFormatter (no override ❌)

ImageFormatter correctly overrides calculateDependencies() to add the image style as a config dependency, and onDependencyRemoval() to handle style deletion gracefully. However, both methods live on ImageFormatter itself — not on the shared ImageFormatterBase. So ImageUrlFormatter, which also extends ImageFormatterBase and also has an image_style setting, inherits only the generic no-op from PluginSettingsBase.

History

This was identified during the original review of ImageUrlFormatter in #2517030:

  • Comment #7 (mondrake): flagged the missing dependency, referencing #2479487
  • Comment #75 (mondrake): "Shouldn't ImageFormatter::calculateDependencies() and ImageFormatter::onDependencyRemoval() just
    introduced in #2479487 be also moved to ImageFormatterBase?"
  • Comment #77 (amateescu): claimed it was addressed in a patch revision

The fix was never committed. The current code in Drupal 11.x still has both methods exclusively on ImageFormatter only.

Proposed resolution

Move calculateDependencies() and onDependencyRemoval() from ImageFormatter to ImageFormatterBase, so that all
formatters extending it (including ImageUrlFormatter and any future subclasses) automatically declare the image style dependency.

Remaining tasks

  • Move the two methods to ImageFormatterBase
  • Add a kernel test asserting that ImageUrlFormatter declares the image style dependency
  • Verify ResponsiveImageFormatter is not affected (it has its own override)

Versions affected

All versions since ImageUrlFormatter was added to core (Drupal 10.1+ through current 11.x).

(Issue summarized with the use of Claude Opus 4.6)

Comments

baluertl created an issue. See original summary.

quietone’s picture

Version: 11.x-dev » main

@baluertl, The issue summary reads like it was generated using an AI tool. The policy on the use of AI when contributing to Drupal includes that the use of AI must be disclosed. I suggest reading that to be aware of the expectations of the Drupal community and the consequences for violations of the policy.

Issues for Drupal core should be targeted to the 'main' branch, our primary development branch. Changes are made on the main branch first, and are then back ported as needed according to the Core change policies. The version the problem was discovered on should be stated in the issue summary Problem/Motivation section. Thanks.

baluertl’s picture

Issue summary: View changes

quietone Indeed, I used Claude to summarize the issue. Thanks for pointing out the community guideline; I was unaware of its existence at all.