Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Part of #1966246: [meta] Introduce specific annotations for each plugin type
In addition to adding a dedicated annotation type, this experiments with altering the plugin discovery directory:
s/Plugin/ckeditor/plugin/CKEditorPlugin/
Comment | File | Size | Author |
---|---|---|---|
#9 | ckeditor-1986988-9.patch | 7.67 KB | tim.plunkett |
#7 | ckeditor-1986988-7.patch | 7.7 KB | tim.plunkett |
#1 | ckeditor-1986988-1.patch | 12.19 KB | tim.plunkett |
Comments
Comment #1
tim.plunkettVoilà.
Comment #2
quicksketchWow, this is *great*! It seems like the correlation between the directory name and the annotation is arbitrary, right? Of course it makes sense that they would be the same thing (i.e. @CKEditorPlugin lives in lib/Drupal/ckeditor/CKEditorPlugin), I'm just curious if you could make them different (though I don't think that would be recommended).
So yay! Eliminating 2 nested directories. I'd love to see this pattern applied to all modules.
However, I still don't think this reduces the importance of eliminating the "Drupal/[module_name]" nested directories in #1971198: [policy] Drupal and PSR-0/PSR-4 Class Loading. Combined with this approach we could end up with simply glorious module structures like this:
With NO redundancy and NO unnecessary nesting. Ah... a man can dream.
Anyway, considering this particular issue. This 100% gets my vote as a conceptual approach to naming plugin directories.
Comment #3
tim.plunkettThe directory CKEditorPlugin and the Annotation @CKEditorPlugin are coincidentally named the same. They do not have to match.
However, while we could decide to remove /Plugin/ from each type, not ever module would benefit from removing the /$owner/ directory.
For example, I would much prefer
lib/Drupal/[module_name]/Views/Display
lib/Drupal/[module_name]/Views/Style
lib/Drupal/[module_name]/Views/Row
lib/Drupal/[module_name]/Views/Filter
to
lib/Drupal/[module_name]/ViewsDisplay
lib/Drupal/[module_name]/ViewsStyle
lib/Drupal/[module_name]/ViewsRow
lib/Drupal/[module_name]/ViewsFilter
etc.
But in a module where you will only have one or two plugin types, this sort of simplication could be done.
And yes, this has absolutely nothing to do with the lib/Drupal/[module_name] bit, let's not even mention it again in any of these issues.
Comment #4
quicksketchAgreed on all counts. :)
Anyway, still excited to see this pattern applied everywhere in which it makes sense, especially modules that only provide a few plugin types. This situation is even more helpful because it eliminates confusing terminology between "Drupal plugins" and "CKEditor plugins", which are very different things, but implementation-wise are combined together.
Comment #5
yched CreditAttribution: yched commentedThis comes at the price of having to define a custom discovery on top of annotationDiscovery...
Do we expect all plugin types to have to ship their own discovery classes ? (and if not, why would it make sense for CKEditor plugins specifically ?)
Also, the .../[owner]/[plugintype]/MyPlugin.php is kind of long when stacked on top of the PSR-0 prefixes, but it guarantees against name clashes between plugin types defined by different systems (e.g. Views might not be the only one that wants to define 'handler' plugins).
It also provides easier human discoverability IMO. When evaluating a contrib module and trying to figure out which plugins it provides for which systems, and figuring those out vs other classes provided by the module (event listeners, plugin managers, straight classes...), having a Plugins directory next to a Listeners directory in at the top of /lib/Drupal/[module] is helpful IMO.
In short: PSR-0 makes excruciating folder paths, but *some* structure below the dumb psr prefix is precious, I'm not sure flattening things there is the right approach ?
Comment #6
Wim LeersI hate the nested folder structure as much as anyone probably, but…
I agree with yched that protecting against name clashes is a must-have.
E.g. foredit.module
, it seems this is failing/clashing withckeditor.module
:I probably misinterpreted that, but people who know/understand this better than I do, please do take a look at that issue.UPDATE: ignore this example, I indeed misinterpreted this.
(See #1987140-6: Add a dedicated @InPlaceEditor plugin annotation.)Comment #7
tim.plunkettHere is the non-controversial patch, no directory structure changes.
Comment #8
quicksketchSince this screams of bikeshed (and has little to do with CKEditor specifically), let's discuss shortening in a dedicated topic: #1987298: Shorten directory structure and PSR-0 namespacing for plugins.
Comment #9
tim.plunkettI don't know if this qualifies as irony, but I personally find it hilarious that the bikeshed issue got in before this was RTBC. :)
Straight reroll.
Comment #10
quicksketchA worthy diversion, IMO.
Applied patch and tested manually. Everything still working correctly. Our individual plugins are being found and work like before. Code looks good to my review.
Comment #11
alexpottCommitted 9b6caf5 and pushed to 8.x. Thanks!
Comment #12
quicksketchThanks @alexpott! I'm working on the companions to this one:
#1987140: Add a dedicated @InPlaceEditor plugin annotation
#1992744: Add a dedicated @Editor plugin annotation