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.
In #1987298: Shorten directory structure and PSR-0 namespacing for plugins we combined the $owner and $type into $subdir.
However, \Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery::getPluginNamespaces() hardcodes $namespaces\Plugin\$subdir
, preventing any true flexibility.
In addition, it also requires a $subdir, preventing plugins from residing in top level directories.
Now that #2042545: Annotation parsing should ignore @file doxygen is in, we can have plugin files wherever we want, but not by using AnnotatedClassDiscovery.
This patch does three things:
- Makes $subdir optional, and moves it to be the second parameter for AnnotatedClassDiscovery
- Forces the plugin manager to declare the full subdir (including Plugin\)
- Adds test coverage for placing a plugin at the top level (
Drupal\$provider
)
Comment | File | Size | Author |
---|---|---|---|
#13 | plugin-2043379-13.patch | 33.91 KB | tim.plunkett |
#13 | interdiff.txt | 2.82 KB | tim.plunkett |
#10 | plugin-2043379-10.patch | 32.56 KB | tim.plunkett |
#9 | plugin-2043379-9.patch | 33.83 KB | tim.plunkett |
#9 | interdiff.txt | 2.94 KB | tim.plunkett |
Comments
Comment #1
tim.plunkettComment #3
tim.plunkettMissed a spot.
I also reduced the scope somewhat and did not move the tours/tips.
Interdiff is just the bug fix.
Comment #3.0
tim.plunkettReduce scope
Comment #4
dawehnerDoes that mean that we will potentially be able to reuse the class for the EntityType patch later?
$subdir needs better docs. Any reason to not force the variable and skip the boolean part? Then we could also get rid of specifying the namespaces first, which feels wrong.
Comment #4.0
dawehnerUpdated issue summary.
Comment #5
neclimdulSeems reasonable but I'm curious
1) why are we changing the argument order?
2) does this solve any problems or is this just a cleanup?
Comment #6
tim.plunkettThis is the reason I swapped them.
Otherwise it would have read
If you don't think we should swap them, that's fine. But I needed to touch all of those to add in the Plugin/ for the subdir...
The answer to @neclimdul's #2 is what @dawehner said first.
It will allow us to change
$this->discovery = new AnnotatedClassDiscovery($namespaces, 'Plugin/Core/Entity', $annotation_namespaces, 'Drupal\Core\Entity\Annotation\EntityType');
to
$this->discovery = new AnnotatedClassDiscovery($namespaces, FALSE, $annotation_namespaces, 'Drupal\Core\Entity\Annotation\EntityType');
And move \Drupal\node\Plugin\Core\Entity\Node to \Drupal\node\Node where it belongs.
Comment #7
neclimdulGotcha. I didn't have any objection but neither point was in the summary so it didn't make any sense.
Comment #8
larowlanStruggling to find anything wrong with this... so I guess that means +1 RTBC from my perspective.
I really like the possibilities this and custom annotation classes open up.
Comment #9
tim.plunkettThanks for pointing out the $subdir, that needed some love.
Comment #10
tim.plunkettAfter further discussion with @dawehner, decided to switch back the parameters after all.
Comment #11
dawehnerThank you very much.
Comment #12
alexpottI think we need to explain that of the possible boolean values only FALSE is valid and what it does.
I think we should keep the comment that says $subdir will be appended to the namespaces (if provided).
Comment #13
tim.plunkettRevisiting this, we don't need it to be FALSE, we can have an empty string. It's more intuitive to me that way.
Comment #14
EclipseGc CreditAttribution: EclipseGc commentedIf that passes I'm very ++ to this. I'm not fond of the 'Plugin/Whatever' nomenclature having to be explicit, however, it's worth the flexibility we get from doing it. I'm RTBC assuming green on 13.
Eclipse
Comment #15
alexpottCommitted d88a2be and pushed to 8.x. Thanks!
Not sure if we need to update any change notices... eg. https://drupal.org/node/1704454 or review the documentation https://drupal.org/node/1637614
Comment #16
tim.plunkettI don't think we need a new one. I updated both of those you linked, after searching through other change notices.
Comment #17
tim.plunkettComment #19
claudiu.cristeaLanded here because I searched a solution for my scenario: I need to discover annotation plugins in and bellow subdir. Supposing that the subdir is set to
Plugin/ImageToolkit/Operation
. I want that next classes to be discovered as being of the same plugin type:Plugin/ImageToolkit/Operation/gd/Crop.php
Plugin/ImageToolkit/Operation/gd/Resize.php
Plugin/ImageToolkit/Operation/imagemagick/Crop.php
(may live in a contrib)Comment #20
claudiu.cristea#2121541: Allow recursion when discovering annotated plugins is addressing my needs from #19.
Comment #20.0
claudiu.cristeafix typo