Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 302501

Allow base plugin definition to be altered before derived

$
0
0

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


Viewing all articles
Browse latest Browse all 302501

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>