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:
- Alter base definitions in Discovery, the discovery class needs a ModuleHandler instance and a hook name.
- 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
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:
Comments
Comment #3
el7cosmosComment #4
el7cosmosComment #6
el7cosmosComment #7
acbramley CreditAttribution: acbramley at PreviousNext for Service NSW commentedAdding 2 related issues that may make this obselete.
Comment #8
quietone CreditAttribution: quietone at PreviousNext commentedThis rang a bell.