Closed (fixed)
Project:
Drupal core
Version:
9.5.x-dev
Component:
plugin system
Priority:
Normal
Category:
Plan
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
10 Apr 2013 at 07:37 UTC
Updated:
7 Feb 2024 at 23:09 UTC
Jump to comment: Most recent
Comments
Comment #1
msonnabaum commentedTotally agree with the current summary.
Additional benefits:
- Improved DX because we're putting an emphasises on the domain instead of the "system". I don't need to know that Entity types are plugins, I just need to know what metadata I need to provide for my EntityType.
- Opportunity for custom validation/mapping in the constructor of the custom annotation class. I'd assume this is possible somehow with Plugins already, but doing it in the annotation class that you own is very intuitive and simple.
Comment #2
xjmComment #3
quicksketchPerhaps we should introduce both @PluginID and @PluginLabel, which provides a human-readable name. Hopefully this would allow removal of pseudo-function @Translate() in our annotations.
We would have something like:
Note I removed module entirely from this definition, since AFAIK, we can auto-determine this information anyway and it doesn't need to be defined in the annotation at all.
If we know that @PluginLabel is always translated, there's no need to wrap @Translate() around every single instance, any more than we wrap t() around menu titles and descriptions.
Comment #4
tim.plunkettIt will be
@PluginID("system_help_block"), the parentheses and quotes are required.I haven't looked into stacking multiple annotations yet, I will.
After a talk with EclispeGC, I changed our goal from removing @Plugin outright, to just not using it anywhere. It will be much easier to get started for contrib if they have @Plugin to use.
Comment #5
msonnabaum commentedI dont know if we need another annotation for that. Each Annotation class should know which keys need to be translated, so it can just do that in its constructor. I dont see a reason to keep @Translate around.
Comment #6
eclipsegc commentedwell, I guess if we never want any strings in a plugin to be simply identified as translateable sure. I think there's still this fundamental ideal that we should be limiting plugin definitions in some way, and I don't really feel that's realistic. Having spoken with tim on this topic today at length, I'm not really opposed to a lot of these changes for the sake of organizing things further, but the Plugin class is so permissive because info hooks are, and it's replacing that. I don't know of any info hooks that we actively prevent alteration on and since plugins strive to be even more generic than most info hooks of the past, I'd prefer we not presume too much about a plugin's use case and prevent others from using it.
That being said there are probably use cases where we can get away with it (various views plugins for example), but this is extending the system in order to limit it, and I just don't want to see that become our default process or remove the more permissive system in favor of this one. Which brings me back around to Translate. Removing that class doesn't buy us anything, and in fact loses us quite a bit since now providing translateable strings (like description?) becomes something the developer has to deal with.
There're a lot of good ideas about very focussed use cases, and that's ok, but I'd prefer the generic use case classes not be targeted for any sort of removal. They're there for a good reason. If we want to expand the annotations we support with some focussed goal in mind, I'm ++ to that.
Eclipse
Comment #6.0
eclipsegc commentedAdjusted goals
Comment #7
tim.plunkettAdded #1967294: Add a dedicated @EntityType annotation to the issue summary.
Comment #7.0
tim.plunkettUpdated issue summary.
Comment #7.1
tim.plunkettadded table for sub-issues
Comment #7.2
tim.plunkettadd table formatting
Comment #7.3
tim.plunkettUpdated issue summary.
Comment #8
tim.plunkettAny of these extending from @Plugin (most of them) will be blocked on #1967420: Allow Core\AnnotatedClassDiscovery to pass all parameters to the constructor of Component\AnnotatedClassDiscovery.
Comment #9
tim.plunkettTagging.
Comment #9.0
tim.plunkettUpdated issue summary.
Comment #9.1
tim.plunkettUpdated issue summary.
Comment #10
tim.plunkettTagging
Comment #10.0
tim.plunkettUpdated issue summary.
Comment #10.1
tim.plunkettUpdated issue summary.
Comment #10.2
dawehneradded an issue for views plugins
Comment #10.3
dawehneradded issue for aggregator module
Comment #10.4
ParisLiakos commentedFix aggregator issue links
Comment #11
dawehnerLinking an issue how to document @Translation need: #1969970: How to document needed @Translation on dedicated annotation classes
Comment #11.0
dawehneradded imagetoolkit plugin annotation
Comment #12
David_Rothstein commented1. I'm not sure it accomplishes that since the code you will write for it still lives under a directory named "Plugin".
2. Is this even a good idea? When people are implementing hooks we don't try to hide that it's a hook. Why should plugins be different?
Otherwise, this proposal makes a lot of sense to me. To address the above, I'd just suggest that "plugin" be somewhere in the class name, and that the class name be as predictable as possible based in the name of the plugin that uses it. So for example @EntityPlugin rather than @EntityType.
I am not sure how in-scope that is for this issue (or how this issue would fix it) but I have gotten that impression as well, that plugin annotations are being overused right now (though never looked into it carefully enough to prove it). Conceptually, annotations are very similar to module .info files, so for typical plugins I don't see why annotations would need to contain much more than the kinds of basic information found in .info files. If this issue can fix that somehow, I'm all for it.
Someone has to deal with it either way, right? I would prefer it be the person defining the plugin type than the person implementing the plugin.
Also, aren't a lot of translatable strings in plugins throughout core using a common set of keys (like "label", "description", etc)? If so, couldn't the base Plugin annotation class provide a method which translates those? Then the plugin type author would only have to override it (and call t() themselves) in the rare case where their annotations are using translatable strings with other keys.
I think it would be great if @Translation could go away - one less syntax for module develpers to have think about...
Comment #13
tim.plunkettI have not brought it up in any issue yet because I don't want to have this fight quite yet, but the code I got in to support the move to custom Annotations can also help us alter the path based on plugin type.
For 98% of plugin types, we either want to be told its a plugin, or wouldn't be confused by that.
Entity types are different. We can now move \Plugin\Core\Entity to just \EntityType, like \Drupal\node\EntityType\Node, or \Drupal\taxonomy\EntityType\Vocabulary.
That's for another issue, I don't even want to hear pros and cons of that now.
@Translation isn't on the chopping block anymore right now, because localize.drupal.org will need it, or some other identifier, instead of t() when parsing files to find translatable string.
If we want to shift the burden off of implementors and onto l.d.o, that's a conversation you should have with Gabor :)
Comment #13.0
tim.plunkettAdded magical @ sign
Comment #13.1
tim.plunkettUpdated issue summary.
Comment #13.2
damiankloip commentedAdded CKEditorPluginManager issue #
Comment #14
quicksketch@tim.plunkett introduced an interesting pattern in #1986988: Add a dedicated @CKEditorPlugin annotation that could be applied to all plugins. Essentially it combines the $owner and $type variables from the table above into a single $owner$type namespace (or just $type in the case that $owner and $type are the same). i.e.
block/blockcould becomeBlockandckeditor/plugincould becomeCKEditorPlugin. This results in less directory nesting and shorter namespaces, but at the cost of clarity and hardline namespacing.Bike-shed discussion commencing at #1987298: Shorten directory structure and PSR-0 namespacing for plugins
Comment #14.0
quicksketchAdded edit editor plugin annotation issue.
Comment #14.1
tim.plunkettUpdated issue summary.
Comment #14.2
tim.plunkettUpdated issue summary.
Comment #14.3
damiankloip commentedAdded condition conversion issue
Comment #14.4
quicksketchAdding Editor module.
Comment #14.5
tim.plunkettAdjusted $owner/$type
Comment #15
jhodgdonI just edited the issue summary to add a link to this related sub-issue:
#1970900: Update standards doc on plugin annotations; add @defgroup annotation
Comment #15.0
jhodgdonAdd link to issue 1970900
Comment #15.1
tim.plunkettUpdated issue summary.
Comment #15.2
tim.plunkettUpdated issue summary.
Comment #15.3
tim.plunkettTypedData
Comment #16
catchLooks like this is all done now? Please re-open and stick the remaining issues in the summary if not.
Comment #16.0
catchUpdated issue summary.
Comment #17
amateescu commentedNot yet :( I updated the summary with the issue for FieldWidget and the one where layout.module was removed, but we still have ArchiverManager, ConstraintManager and ResourcePluginManager.
Comment #18
joachim commented> It provides no place to document the keys used by that particular annotation
Annotation classes only go some of the way.
If you look at https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Annotation..., compared to https://api.drupal.org/api/drupal/modules!system!system.api.php/function... --
- we've lost the general intro to the concept
- we've lost readability. The list of class properties is much harder to read down that the properties docblock we had for the hook
- we've lost sample code.
- that means we've also lost the sample values for each property that are given in the sample code
Furthermore, there are new concepts in the plugin system that developers need to know about but which aren't represented here:
- what's the subdirectory to use for the plugin?
- what's the name of the service to get the plugin manager?
These are all things that need to be better joined up in the docs so that developers can actually make sense of how it fits together.
If the issue here is improving DX for working with plugins, then we need to think of the bigger picture.
Edit: bigger picture #2086397: Find a consistent way to document plugin types.
Comment #18.0
joachim commentedAdded the issue where FieldWidget was introduced and where layout.module was removed from core.
Comment #19
les limComment #20
les limComment #21
les limComment #22
les limComment #23
les limComment #24
mgiffordComment #25
mgiffordComment #26
mgiffordComment #27
les limAdded beta evaluation.
Comment #28
xjmComing here from #2195573-21: Add a dedicated @LanguageNegotiation annotation class. "Improving developer experience" by itself doesn't make the change acceptable during the beta. However, the point of this issue is also to make it possible to document the keys for each annotation, which is prioritized for sure. Finally, there are only a handful of these that did not get done pre-beta. So I'm inclined to grant an exception and consider these as prioritized changes.
As far as I can see, there are only three child issues remaining:
Comment #29
tim.plunkett2) I need to reread it, but I think the PluginTestFruit was our non-custom annotation test coverage, so I think we might want to keep that?
3) You'll have to check with Rules, but it doesn't affect panels/page_manager at all.
Comment #30
eclipsegc commentedYeah, it'd be really great to get all of these. It'd give us the option of making the Plugin annotation abstract, which I think is probably favorable before 8.0.0 release (since it would heavily re-enforce this same paradigm in contrib, which I think we all want. Care to comment on that Tim?
Eclipse
Comment #31
xjmFrom @berdir in IRC:
Comment #32
eclipsegc commentedWe're enforcing an optional core standard on contrib if we make Plugin Annotation abstract. I think that's a good idea, but it's not something to sweat horribly at this point. Really either way. We either value everyone adopting this standard or we don't. For the moment, I think there's sufficient examples within core that people are likely to follow the standard anyway, it's just a matter of forcing it or not. Not like they couldn't extend Plugin and then keep doing what it does today, so we really have no authority at all :-D
Eclipse
TL:DR; I think it's a good idea, but it doesn't really matter so, it probably doesn't factor into the decision.
Comment #33
les limThere's already a follow-up issue for making Plugin abstract at #2195557: Make Drupal\Component\Annotation\Plugin abstract. That issue should really have a separate beta evaluation -- it's not required for this issue and doesn't present any reasons to block it.
Comment #34
eclipsegc commentedCorrect, I'm saying quite the opposite. This issue is a requirement of that issue... not vice versa. If we don't provide a custom annotation for each plugin type, we cannot ever make Plugin abstract. That's all I'm saying.
Eclipse
Comment #35
xjmAgreed, for this issue, we should only be discussing the issues in #28, so that we can unpostpone them if appropriate.
@alexpott and @fago haven't commented yet. @alexpott said in IRC:
Comment #36
fagoyeah, I'm fine with the Constraint annotation class being added. It does not touch Rules at all so far.
Instead I think it's more related to people that need to customize their entity validation and are providing custom constraints for that - as berdir mentioned in #31. If we really want to take care of them, we could still support @Plugin for those also maybe? But +1 on generally fixing this, it would be weird to have only constraint plugins use @Plugin.
Comment #37
xjmAlright, thanks everyone. Based on #36 and above I'm going to unpostpone those two child issues for @Constraint and @LanguageNegotiation.
Comment #38
les limProposed change record here: https://www.drupal.org/node/2484461
Comment #39
eojthebraveI reviewed the change record. And it looks good. Thanks Les. Though I suppose we should probably wait to publish it until the @Constraint and @LanguageNegotiation issues are fixed.
Comment #40
eric_a commentedIs this meta open for #2200953: Add a dedicated @PluginTestFruit annotation class only? Is it worth holding up publishing a change record for?
Comment #41
les limI've updated that last issue to suggest that we keep it using @Plugin, since we technically still allow contrib to do that. If so, we can publish the change record and close out the whole meta.
Comment #50
andypostI think cr could be published and issue closed as there's only one child issue left
Comment #55
quietone commentedThere is one issue left here to complete and I have changed the parent of that issue to #3396165: [meta] Convert all core plugin types to attribute discovery. I have updated the CR here to list the plugin types changed that did not have a separate change record. This CR is now published with the date adjusted to 2015.
Therefor, I am closing this issue as fixed.