Allow base plugin definition to be altered before derived

Created on 19 May 2023, about 1 year ago
Updated 24 January 2024, 5 months ago

Problem/Motivation

At the moment, altering a plugin is done via hook_<plugin_alter_info>_alter, this happens after derivatives are already defined. The problem is, we can't change for example the deriver class because it's already too late.

In our case, we have layout_builder and block_content enabled and also have these block plugins:

  • \Drupal\layout_builder\Plugin\Block\ExtraFieldBlock
  • \Drupal\layout_builder\Plugin\Block\FieldBlock
  • \Drupal\block_content\Plugin\Block\BlockContentBlock

Depending on the number of entity types and their fields, those base plugins can have a vast number of derivatives, and in our case, it gives OOM when visiting a page after rebuilding the cache. We try to remove not needed derivatives via hook_block_alter, but this is too late because the $definitions array is already too big and consuming much memory. Only when we filtered out not needed derivatives in our custom deriver class, then the OOM problem solved.

I haven't found any use case other than block plugins, this may be a specific issue with the block plugin manager.

Steps to reproduce

Proposed resolution

Provide a hook alter or dispatch event before calling \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDerivatives so that the base plugin definition can be altered.

I see two approaches:

  1. Alter base definitions in Discovery, the discovery class needs a ModuleHandler instance and a hook name.
  2. Alter base definitions in PluginManager, the discovery class needs to provide a method to return base plugin definitions and make getDerivatives method public.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Active

Version

11.0 🔥

Component
Plugin  →

Last updated about 15 hours ago

Created by

🇮🇩Indonesia el7cosmos 🇮🇩 GMT+7

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

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

Production build 0.69.0 2024