Updated: Comment #4
Problem/Motivation
In Drupal 7, it was common for modules like Views to provide plugins on behalf of other modules. Like node views handlers:
if (!function_exists('node_views_api')) {
function node_views_api() { return views_views_api(); }
}
We need the annotated plugin version of that.
Proposed resolution
Force DefaultPluginManager to check for a module being enabled.
Remaining tasks
None
User interface changes
N/A
API changes
Plugins whose 'provider' is a disabled module will not be available
To do this the following method signatures are changing:
- DefaultPluginManager::__construct() now has the module handler injected
- DefaultPluginManager::alterInfo() no longer requires the module handler
Related Issues
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #78 | interdiff-2053153-78.txt | 3.17 KB | damiankloip |
| #78 | 2053153-78.patch | 44.12 KB | damiankloip |
| #68 | plugin-2053153-68.patch | 38.94 KB | aspilicious |
Comments
Comment #1
tim.plunkettComment #2
tim.plunkettWe already have the module handler! Woot.
Comment #3
aspilicious commentedI tested this with Display Suite plugins. (The reason why we started this discussion in irc)
It works great so it would be awesome to see this in core to prevent duplication in contrib.
Comment #4
tim.plunkett@EclipseGC suggested doing this directly in DefaultPluginManager.
Comment #5
dawehnerPHP, seriously.
As tim mentioned on IRC, this basically makes the module handler required for the default plugin manager.
Comment #7
dawehnerThis adds the module handler.
Comment #9
dawehnerSome more missing usages of the module handler.
Comment #11
dawehnerJust another rerole, hopefully it is green now.
Comment #13
olli commented#11: plugin-2053153-11.patch queued for re-testing.
Filed #2056713: Random test failure in Drupal\rest\Tests\NodeTest
Comment #15
olli commented#11: plugin-2053153-11.patch queued for re-testing.
#2056713: Random test failure in Drupal\rest\Tests\NodeTest is in.
Comment #16
tim.plunkettRandom failures aside, this looks great. Thanks!
Comment #16.0
tim.plunkettUpdated for new approach
Comment #17
alexpottThis change is important for contrib to be able to provide plugins for optional core modules such as views.
Comment #18
alexpottI did not add the needs tests tag d.o! this patch has tests
Comment #19
alexpottNeeds a reroll
Comment #20
tim.plunkettStraight reroll, I added another method to BlockManager which changed the patch context.
Comment #22
tim.plunkettMeh, we have a new one.
Comment #23
damiankloip commentedNeeds a reroll, but just wondering, should the alter be moved after the filtering out of disabled module definitions?
Comment #24
dave reidFiled a duplicate issue in #2083405: Modules should easily be able to provide plugin implementations on behalf of core modules. This is really important for any contrib module that provides it's own API.
Comment #25
tim.plunkettAssigning so I don't lose track
Comment #27
tim.plunkett#25: plugin-2053153-25.patch queued for re-testing.
Comment #29
tim.plunkettI can install minimal and standard, PHP 5.3.14 and 5.4.4, from drush and from the UI.
:(
Comment #30
tim.plunkettWill figure this out after #2084513: Annotation class loading could be more elegant., which changes all of these method signatures.
Comment #31
tim.plunkettRerolled after that
Comment #33
tim.plunkettUpdated the recently added SearchPluginManager.
Comment #35
tim.plunkettAlso missed AggregatorPluginManager, and had the order wrong for ImageToolkitManager.
Comment #37
tim.plunkett...
Comment #39
tim.plunkettMore stupid mistakes.
Comment #41
tim.plunkett#39: plugin-2053153-39.patch queued for re-testing.
Comment #42
thedavidmeister commentedDo we need to do anything here for things like ActionManager that don't extend DefaultPluginManager?
Also, nitpick but:
// If this plugin was provided by a Drupal module, ensure it is enabled.I would read that to mean "if the module is not enabled, enable it now", rather than "Do this thing only if the module is enabled".
__construct for TypedDataManager has no documentation. Could we fix that since we're touching that function here and we've modified the docs in other places?
It looks like everything extending DefaultPluginManager has been updated in #39, which is good.
Comment #43
tim.plunkettModules can no longer be disabled anyway, so rewrote that.
Managers that don't extend DefaultPluginManager yet will be fixed in their subissue of https://drupal.org/node/2010412
Comment #44
jibranPatch looks good RTBC for me. Let's see what other thinks.
Comment #45
thedavidmeister commentedI'm happy with the interdiff. This functionality is probably going to be very important for organisation/DX in contrib and custom projects. As per #42 and #44, RTBC :)
Comment #46
aspilicious commentedThis will brake every plugin manager in contrib again so it's better to get this in as fast as possible.
Comment #47
David Hernández commented#43: plugin-2053153-43.patch queued for re-testing.
Comment #48
alexpottPatch no longer applies.
Comment #49
damiankloip commentedMcreroll.
Comment #50
damiankloip commentedGot an nginx error. Let's try again.
Comment #51
damiankloip commentedComment #52
aspilicious commentedYes rtbc++
Comment #53
catch#50: 2053153-49.patch queued for re-testing.
Comment #55
dawehnerThe image toolkits moved to lib/Drupal/Core.
Comment #56
jibranBack to RTBC.
Comment #57
catchCommitted/pushed to 8.x, thanks!
Comment #57.0
catchUpdated issue summary.
Comment #58
tim.plunkettComment #59
star-szrTagging to write up the change record.
Comment #60
xjmTagging "Missing change record", as completing the change record updates here blocks a beta: #2083415: [META] Write up all outstanding change notices before release
Comment #61
les limSo I was just about to write up a quick and easy change record for this, but despite #57, it doesn't look like any of this was actually committed. Definitely needs a re-roll now.
Comment #62
tim.plunkettWow, that sucks.
Comment #63
jibranWrong patch I think.
Comment #64
tim.plunkettahhhhhh ffuuuuuu i can't find the patch locally. And that one was a bear to reroll.
Comment #66
xjmSad kittens.
Comment #67
aspilicious commentedI'l start the initial reroll as I'm the one who actually needs this in contrib asap. :)
Comment #68
aspilicious commentedLets try this one
Comment #69
tim.plunkettThis was "committed" before we even started tagging all of the beta blockers.
Now 4 months later, we still have to do this, and it will change all plugin managers :(
Comment #71
aspilicious commentedI need help with unit tests o_O.
I managed to remove the fatals with some "calculated guesses" ;) but the local task tests are still failing. It must be really simple to fix this but I keep starring at the dots of the unit test output :
Comment #72
aspilicious commentedComment #73
dawehnerThis will do it.
Comment #76
swentel commented'$module_handler = ... ' should go on a new line
Comment #77
damiankloip commentedLooking into this now.
Comment #78
damiankloip commentedOk, so this fixes the issue but it's not pretty. I have overridden the findDefinitions() method so that is also checks for the theme in the provider.
The problem: Introducing the code in findDefinitions() that checks the module handler (moduleExists()) does not check the theme handler also. As ConfigMapperManager is a special snowflake that aggregates a list of module and them directories, and passes that to the YAML discovery.
Comment #79
damiankloip commentedComment #80
dawehnerThese fixes seems to be pretty great!
Comment #81
tstoecklerI'm not sure this really is a safe assumption. Elsewhere in core we do
if ($module_handler->module_exists($plugin_definition['provider']) { well_then_its_a_module() }which is also a little bit weird, but here it's the other way around. I think it is very unfortunate that we're baking in the assumption that a plugin has to come from an enabled module or from something called 'Core' or 'Component' (which is a bug in itself...)Comment #82
tim.plunkettOut of scope, we have to handle whatever AnnotatedClassDiscovery::getProviderFromNamespace() throws at us, which is this.
Plus, this was already "committed", just never pushed.
Comment #83
webchickOk, getting this in while it's hot. For real this time. :)
Committed and pushed (double-checked) to 8.x. Thanks!
Comment #84
les limTagging for change record.
Comment #85
damiankloip commentedIts not a bug. We made a decision that we wanted to support plugins in the core namespace. So that's intended behaviour.
Plus the whole discovery thing is a much bigger issue than this. Which as Tim mentioned, is certainly out of scope.
Comment #86
aspilicious commentedI'm confused what we need here:
Do these one need an update?
https://drupal.org/node/2034535
https://drupal.org/node/2087153
Do we need a seperate one?
Comment #87
tstoecklerThis is in no way out of scope. This is the first place in core that we're assuming that a plugin provide is either an installed module, or 'Core' or 'Component'. That is the problem and that problem is being introduced here.
Anyway, apparently I'm the only one that finds this problematic, so I'll shut up now.
Also, the fact that something was committed before is not in any way a technical justification for a patch.
Comment #88
berdir@aspilicious: Yeah, those two. While at it, I'd suggest you also update the DefaultPluginManager one to specify an annotation class, as it is common for almost all plugin managers.
Comment #89
damiankloip commented@tstoeckler:
No, that is not true. Otherwise, why would we need that bit of code in this patch?! If no plugins were ever found there it would not do anything... Core and Component plugin namespaces are already registered for plugins. If you don't believe me, just take a look at DrupalKernel::buildContainer().
Comment #90
tstoecklerSorry, I seem to be failing at getting the point across. My point is that a plugin 'provider' could just as well be something completely different, in theory. Neither an installed module, nor 'Core', nor 'Component'. On a custom website project, I could for example choose to always register a \Drupal\TstoecklersKickassPlugins namespace as well. That would have worked absolutely fine until this patch. We're baking very intimate Drupal knowledge into the generally Drupal-agnostic plugin system. That's all I'm saying.
I'm well aware that Core and Component can provide plugins, I pushed hard for that.
Comment #91
damiankloip commentedSo you would override the container.namespaces parameter? ok. That's up to you I guess.
Seems like you might as well open up an issue if you feel strongly about it - we can talk about how you would actually do this there (seems riddled with issues). For 99.9% of cases this will not be applicable. We don't really support adding arbitrary plugin namespaces anyway? Although this technically can be done.
This is a much wider issue that should be addressed in isolation I think.
Comment #92
aspilicious commentedSo those 2 are updated, I "modernised" the defaultPlugin one.
Comment #93
tstoeckleryay, apparently I finally managed to make myself clear. Thanks @damiankloip for the patience :-)
Yeah, I don't really feel that strongly about it, I just think it is unfortunate, because we didn't have to make that assumption previously.
Comment #94
berdirThe two updated change notices look fine to me.
I'm not sure if we want a new one as well. We need to at least document how this works somewhere in the plugin system documentation anyway (https://drupal.org/node/1637730 might be a place to add it (also needs an update for this anyway), or one of the related doc pages about discovery? Not sure..
Thinking about it, this is information that might also be interesting for 7.x -> 8.x upgrades (constructor argument change, but the concept of being able to declare plugins for another module and use the provider to have them filtered out). So 1+ to a very short change record that explains that this concepts now exists, possibly with a very simple example if at all and then point to the relevant documentation page.
Comment #95
chx commentedI am not sure about change record but I need to know what -- if anything -- I need to change in the migrate plugin managers and service definitions.
Comment #96
berdir@chx: See https://drupal.org/node/2034535/revisions/view/2778995/6979403
Instead of passing $module_handler to the alter, you pass it to the constructor. That's all. And you need to inject the module handler if you don't do so already.
Comment #97
chx commentedFor the record, the issue title was very confusing for me at least. What happened here is: plugins now have a limited dependency system. Each plugin can depend on at most one module or theme. The value of
providerin the annotation is the name of that module or theme.Comment #98
chx commentedI have drafted a change record now that I understand what this issue is about.
Comment #99
chx commentedI fixed the change notice to say we do not support theme as provider (yet?).
Comment #100
jessebeach commentedChange notice: https://drupal.org/node/2218535
I added a code example to the existing draft change notice by chx and edited the language a little. I also added an API Changes section using the notes from the issue summary. There's also a new link to the Plugin documentation in Drupal 8.
I've added links to the two change notices mentioned by aspilicious in #86.
This satisfies all of the comments about the CN in this issue. I'm marking this as fixed. Please raise concerns if you have them and we'll adjust the wording if needed.