Problem/Motivation
When modules are installed, plugin definitions are cleared.
Breakpoints and Layouts also allow themes to provide plugins, they need to be cleared as well.
Any manager using YamlDiscovery has to pass in the list of directories to search, and these are not updated.
Additionally, the %container.namespaces% parameter is updated by the DrupalKernel, but is also cached by the discovery
Proposed resolution
Reset the discovery in \Drupal\Core\Plugin\DefaultPluginManager::clearCachedDefinitions()
Adjust \Drupal\Core\Extension\ThemeInstaller::resetSystem() to match \Drupal\Core\Extension\ModuleInstaller
Remaining tasks
Reroll
Review
Commit
User interface changes
N/A
API changes
N/A
Data model changes
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #37 | 2860346-37.patch | 4.91 KB | nikhil_110 |
| #36 | 2860346-nr-bot.txt | 144 bytes | needs-review-queue-bot |
| #34 | 2860346-34.patch | 4.02 KB | smustgrave |
| #4 | 2860346-discovery-4.patch | 3.88 KB | tim.plunkett |
| #2 | 2860346-discovery-2-PASS.patch | 2.26 KB | tim.plunkett |
Comments
Comment #2
tim.plunkettComment #4
tim.plunkettComment #5
dawehnerNice fix!
Does this maybe fixes https://twitter.com/weitzman/status/839605704243691521 ?
Comment #6
tim.plunkettThat half and the other half in conjunction should fix that!
Comment #7
alexpottDoes this change mean that we might break contrib/custom plugin managers if they, like EntityTypeManager, do some custom discovery and don't implement getDiscovery()? And if so how are we going to prevent them breaking?
I think this comment could do with being fleshed out a bit to explain that this is to test that theme installation clears the breakpoint definitions - right?
Comment #8
tim.plunkett1) If we made this change to \Drupal\Component\Plugin\PluginManagerBase, that would indeed be a huge issue.
But \Drupal\Core\Plugin\DefaultPluginManager will be just fine, and anyone (like EntityTypeManager) not using it is currently broken.
ETM explicitly opts out of using derivatives, but it is not documented. To enable derivatives would be a simple as deleting the new getDiscovery override added here.
But the real bug with ETM was that it did not pass the $plugin_definition_annotation_name to parent::__construct()
2) Yep
Uploading 2 patches, the first just simplified ETM while leaving getDiscovery in place, with an interdiff against #4.
The second removes ETM::getDiscovery, with an interdiff against the other patch.
Comment #9
alexpottI don't think we should open up entity types to derivatives. Feels a bit out-of-scope here and would need further consideration.
Comment #10
tim.plunkettOkay, so the second patch attached is fine?
Comment #11
dawehnerI don't get the entire discussion about derivatives of entity types. We have them effectively already with
hook_entity_type_build()Comment #12
tim.plunkettRegardless of what it could be used for, or what other approaches exist, the question here is: should EntityTypeManager use ContainerDerivativeDiscoveryDecorator?
Comment #13
tim.plunkettOr more accurately: is there a reason to have EntityTypeManager explicitly opt out of using ContainerDerivativeDiscoveryDecorator?
Comment #14
dawehnerI don't see a reason to opt out.
Comment #15
dawehnerThis looks great for me
Comment #17
naveenvalechaBack to RTBC per #15
Comment #18
alexpottThe only reason I see is that is opted out in HEAD and this patch is opting it in. Yes we get plugin discovery resetting but we also get more functionality. In my opinion the entity API does not need more ways to achieve the same thing. This is why I think https://www.drupal.org/files/issues/2860346-discovery-8.patch is the safer patch to go for.
Comment #19
wim leersAs somebody who knows the plugin system implementation details not very well: why not rely on the
config:core.extensioncache tag?Basically:
Comment #20
alexpottSetting back to needs work for #19 - that sounds like a really good solution imo - easily the most robust.
Comment #21
tim.plunkettThat will clear the cache of definitions, which is fine. But that already happens due to a call to
\Drupal::service('plugin.cache_clearer')->clearCachedDefinitions();.This issue is about the actual discovery object itself.
Comment #22
dawehner@tim.plunkett
Just to understand you correctly, this is some static caching, right? I'd have expected that every service is reseetted properly on module install / theme install ...
Comment #26
tim.plunkettThis is the same problem raised in #3001284-28: Allow plugin derivers to specify cache tags for their definitions
Comment #34
smustgrave commentedThis came up as daily bug smash target.
This appears like it could still be relevant in D9.5 (but someone correct me if I'm wrong)
Sounds like the issue brought up in #19 was addressed in #21
Rerolled for 9.5. Tried generating interdiff but had an issue since the original patch was from a while ago. But used 2860346-discovery-8.patch to start.
Had merge conflicts in
core/lib/Drupal/Core/Entity/EntityTypeManager.php
core/lib/Drupal/Core/Extension/ThemeInstaller.php
core/modules/breakpoint/tests/src/Kernel/BreakpointDiscoveryTest
That I had to manually resolve.
Comment #36
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #37
nikhil_110 commentedAttached patch against Drupal 10.1.x
Patch #34 is not applied for Drupal 10.1.x so Inter-diff file is not added.
Comment #38
alexpottThis dependency should be injected - all the others are in class already.
Why is this necessary? Both install and uninstall are already calling
$this->themeHandler->reset();Comment #40
alex.skrypnyk#34 states that #19 was addressed in #21, but it is not actually clear whether #21 meant that in a context of initially provided patch or in general:
So #19 is not actually addressed if the patch is not applied and it can be an easier solution.
https://www.drupal.org/node/3204271 has a similar issue that is possible caused by already cached definitions.
For example, for LayoutPluginManager, adding of the cache tag based on the installed extensions resolves the issue