Problem/Motivation
See also
#2821191: Allow object-based plugin definitions to be processed in PluginDependencyTrait
#2818653: Allow object-based plugin definitions to be processed in DefaultPluginManager::findDefinitions()
ContextHandler can filter plugin definitions by context, but it only supports array-based plugin definitions with a context
key containing context definitions. Now that some plugin definitions in core are class-based, we need to extend this functionality to work with those definitions.
Proposed resolution
Add a new interface for context-aware plugin definitions and allow ContextHandler to filter plugin definitions which implement it.
Remaining tasks
Patch, tests, commit.
User interface changes
None.
API changes
A new interface and trait will be added to the plugin context system.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#16 | interdiff-2961822-6-16.txt | 644 bytes | phenaproxima |
#16 | 2961822-16.patch | 13.08 KB | phenaproxima |
#7 | interdiff-2961822--7-FAIL-6.txt | 2.34 KB | phenaproxima |
#7 | 2961822-7-FAIL.patch | 10.61 KB | phenaproxima |
#6 | interdiff-2961822-5-6.txt | 6.09 KB | phenaproxima |
Comments
Comment #2
phenaproximaHere's a first stab at defining the API for this. If this looks good, I'll update ContextHandler and write some tests.
Comment #3
phenaproximaUpdated ContextHandler to work with the new interface. Still needs tests, though.
Comment #4
tim.plunkettI think this should be a trait instead of a class.
My original approach of the guard condition and simple return no longer makes sense with the more complex structure.
I'd combine pluginSupportsContext and getContextDefinitions, and just have it return NULL if there aren't any.
And for getContextDefinitions() it'd be something like (sorry for the pseudocode)
Comment #5
phenaproximaDone!
Comment #6
phenaproximaThis should do the trick for tests -- I adjusted ContextHandlerTest::providerTestFilterPluginDefinitionsByContexts() so that all the plugin definitions are also duplicated as context-aware plugin definition objects.
Comment #7
phenaproximaAs requested by @tim.plunkett on Slack, here is a fail patch to prove that ContextHandler actually filters the plugin definitions correctly. The interdiff is what patch #6 adds in order to get the tests to pass.
Comment #8
phenaproximaChange record written: https://www.drupal.org/node/2979920
Comment #10
phenaproximaFail patch failed, as expected.
Comment #11
phenaproximaThis issue blocks #2976148: Layout-based entity rendering should delegate to the correct section storage instead of hardcoding to either defaults or overrides.
Comment #12
phenaproximaComment #13
phenaproximaComment #14
tim.plunkett#6 looks good, thanks for the CR
Comment #15
larowlanubernit: can just be an if, we returned above
Comment #16
phenaproximaNit fixed. Leaving at RTBC since I fully expect this one to pass.
Comment #17
larowlanAdding review credits
Comment #18
larowlanfixed on commit
Committed 1b66e53 and pushed to 8.6.x.
Comment #20
larowlanpublished change record