I have a problem with a stale plugin-derivatives cache in a kernel test:

  protected function setUp() {
    $this->installConfig(['my_module', 'my_module_test']);

The my_module_test module installs new entities that should produce derived plugins, but when my test class tries to instantiate these plugins, they are not found.

It works if I explicitly call $this->container->get('{my_plugin_manager}')->clearCachedDefinitions() after installConfig(), so it's definitely a stale plugin cache. But I'm worried this problem might happen elsewhere. Is there some way to tag the plugin cache with {my_entity_type}_list so it gets invalidated by new entities? Or do I simply need to invalidate it explicitly whenever I do something that creates new entities?

1 Answer 1


Yes you should do that.

Module install is not really a problem as all plugins are invalidated then anyway, but entities can also be changed in the UI.

See \Drupal\block_content\Entity\BlockContent::postSave() for an example that does that in core.

  • Thanks, the entity's ::postSave is a great idea; so far I had this logic in the form save, which doesn't cover non-interactive stuff. Jul 11, 2017 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.