Config entities implementing EntityWithPluginCollectionInterface should ask the plugins to react when their dependencies are removed

Created on 3 October 2015, almost 10 years ago
Updated 5 September 2025, 12 days ago

Problem/Motivation

When a config entity implementing EntityWithPluginCollectionInterface is reacting on dependency removal, it should ask the plugins from the collections if they want to take some action when their dependencies are about to be removed.

This issue is adding a generic solution for the one fixed in #2562107: EntityDisplayBase should react on removal of its components dependencies β†’ .

Proposed resolution

  1. Add code in ConfigEntityBase::onDependencyRemoval() that tests if the entity implements EntityWithPluginCollectionInterface. If so, iterate through collections and if there are specific plugin dependencies being removed, call the plugin ::onDependencyRemoval() method to allow the plugin to react.
  2. Add a new method onDependencyRemoval() in \Drupal\Component\Plugin\DependentPluginInterface.
  3. Add empty onDependencyRemoval() implementations in base classes implementing DependentPluginInterface with a simple return FALSE;.
  4. Implement one use-case.
  5. Tests.

is reacting on dependency removal, it should ask the plugins from the collections if they want to take some action when their dependencies are about to be removed.

Remaining tasks

None.

User interface changes

None.

API changes

New method \Drupal\Component\Plugin\DependentPluginInterface::onDependencyRemoval().

Data model changes

None.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
Configuration entityΒ  β†’

Last updated 8 days ago

Created by

πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

Live updates comments and jobs are added and updated live.
  • API change

    Changes an existing API or subsystem. Not backportable to earlier major versions, unless absolutely required to fix a critical bug.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • First commit to issue fork.
  • Created MR 13171 with a new approach that is mostly based on the MR for πŸ› Deleting a Media view mode should not result in the deletion of an entire text format Active , combined with some ideas from the patch in #70:

    1. Add new interface Drupal\Core\Plugin\RemovableDependentPluginInterface with method onCollectionDependencyRemoval()
    2. Add code in ConfigEntityBase::onDependencyRemoval() that tests if the entity implements EntityWithPluginCollectionInterface. If so, iterate through collections and if there are plugin that implement RemovableDependentPluginInterfacedependencies::onCollectionDependencyRemoval(), invoke the method on that plugin so it can react by changing its configuration or removing itself from the collection
    3. If onCollectionDependencyRemoval() returns TRUE, then ConfigEntityBase::onDependencyRemoval() will return TRUE, so the config entity's dependencies can be recalculated
    4. Implement two use cases: 1) prevent image styles from being deleted if a module that provides any of its image effects is uninstalled and 2) prevent filter formats from being deleted if a media entity view mode used in a media embed filter is deleted
    5. Add kernel tests for two use cases

    This approach kind of comes at the problem from the other way of the patch. The handling of the dependency removal is done completely in the plugin class, other than the entity invoking the plugin's onCollectionDependencyRemoval() method. The plugin collection and index ID of the plugin instance in the collection are provided as arguments along with the dependencies, so that the plugin instance can be removed from the collection as needed. This approach is kind of based on how Drupal\views\Entity\View\onDependencyRemoval() invokes DependentWithRemovalPluginInterface::onDependencyRemoval() for handler plugins, as well as FieldItemInterface::onDependencyRemoval(), which has the field definition object as well as the dependencies passed in.

    There may need to be tests added to test the dependency removal handling generically. The tests in the MR are kernel tests specific to the the image style and media view mode use cases. The unit tests in #70 no longer apply to the solution.

    Also bumping this to critical, because πŸ› Deleting a Media view mode should not result in the deletion of an entire text format Active combined with πŸ“Œ Deleting filter formats may result in data loss Active can lead to content data loss. There is a case of this actually happening brought up in slack: https://drupal.slack.com/archives/C1BB308HH/p1755719629686569

    Also, with this πŸ› Deleting a Media view mode should not result in the deletion of an entire text format Active is effectively a duplicate, so it perhaps can be closed with credits transferred here.

  • Pipeline finished with Success
    12 days ago
    Total: 5254s
    #591198
  • Pipeline finished with Failed
    9 days ago
    Total: 150s
    #593188
  • Pipeline finished with Success
    9 days ago
    Total: 453s
    #593196
  • Changed the functional test for media to a kernel test, and added a unit test for more generic coverage.

Production build 0.71.5 2024