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

Issue fork drupal-3361447

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

el7cosmos created an issue. See original summary.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

el7cosmos’s picture

Issue summary: View changes
el7cosmos’s picture

Issue summary: View changes

el7cosmos’s picture

Issue summary: View changes
acbramley’s picture

quietone’s picture