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.
Updated: Comment 0
Problem/Motivation
If you write any kind of plugin you need to put this two classes into the file in order to make it working.
Before
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
/**
* @EntityType(
*/
Proposed resolution
Add the @Translation and @{$PluginType} automatically, so the use statement is not needed anymore.
Some more information: http://docs.doctrine-project.org/projects/doctrine-common/en/latest/refe...
After
/**
* @EntityType(
*/
Remaining tasks
Should we remove all the use statements all over core in this issue
User interface changes
API changes
Related Issues
Comment | File | Size | Author |
---|---|---|---|
#13 | plugins-2090353-13.patch | 7.81 KB | dawehner |
#13 | interdiff.txt | 2.7 KB | dawehner |
#10 | interdiff.txt | 3.75 KB | dawehner |
#10 | plugin-2090353-10.patch | 8.06 KB | dawehner |
#6 | plugin-2090353-6.patch | 5.99 KB | dawehner |
Comments
Comment #1
dawehnerThere we go, manually installing standard works for that.
Comment #2
dawehnerThe magic code which makes this possible is in DocParser:
The reason why I had to switch to SimpleAnnotation is because the normal AnnotationReader class does not allow you to specify the namespaces.
Comment #3
larowlanComment #4
dawehnerRemoved the changes in doctrine itself.
Comment #5
damiankloip CreditAttribution: damiankloip commentedI really like this patch, I think just being able to use the core annotation classes is great, and the various plugin implementations using their own (Like Views, ViewsDisplayPlugin etc..) can almost be enforced (kind of).
I guess this is the only issue... :) Have you created an upstream patch?
Comment #6
dawehnerChx suggested to use that piece of code to get the namespace.
Comment #7
chx CreditAttribution: chx commentedSo. Nice!
Comment #8
damiankloip CreditAttribution: damiankloip commentedOh, you don't even need to. Great. Looks good!
Edit: I cross posted in #5 before I saw the patch after it.
Comment #9
tim.plunkettThis is insanely awesome.
EDIT:
To clarify to committers, this only removes a handful of "use" annotation lines to keep the patch down. But this essentially means we'll never need to "use" an annotation in any file.
Comment #10
dawehnerLet's move the drupal core specific code into the core namespace.
Comment #11
EclipseGc CreditAttribution: EclipseGc commentedThis isn't currently used in the Component at all.
I really expected to see the SimpleAnnotationReader here. It's strange that we then override this completely in the Core portion of the code. I expected the namespace of the pluginDefinitionAnnotationName to be added to the reader here and have the Core portion of the code call parent::getAnnotationReader().
Wondering if we can get a sanity check from donquixote on this with regards to PSR-4. If that all checks out, then I'm on board, but I really do think that the substr()/addNamespace() combo here belongs in the Component.
Otherwise I generally like the basic approach here.
Eclipse
Comment #12
EclipseGc CreditAttribution: EclipseGc commentedoops
Eclipse
Comment #13
dawehnerMy idea was to make the component as generic as possible, but sure we can just do it like that.
Comment #15
tim.plunkett#13: plugins-2090353-13.patch queued for re-testing.
Comment #16
tim.plunkettGreat points @EclipseGc, great work @dawehner.
I love that we get to skip this completely.
Comment #17
EclipseGc CreditAttribution: EclipseGc commented++ing the RTBC
Eclipse
Comment #18
webchickHOLY CRAP I LOVE THIS PATCH SO MUCH!!!!
Committed and pushed to 8.x. YEAH!
Needs a change notice.
Comment #19
dawehnerHere is one: [#2096117]
I am wondering whether we should change all the existing ones for all the various plugin ones.
Comment #20
EclipseGc CreditAttribution: EclipseGc commentedYeah, I mean, low priority, but it seems like the sort of thing we should go ahead and begin implementing in our plugins.
Eclipse
Comment #21
swentel CreditAttribution: swentel commentedDoing it for field api: #2094003: Remove use statements in formatters, widgets and field types plugins
Comment #22
jibranJust a silly question Can we do this for contirb as well?
Comment #23
dawehnerThis works for all plugin annotations you define, if your plugin manager supports it specify the plugin annotation. In other
words core modules are just a special case of modules, so contrib modules will just work as well.
Comment #24
ParisLiakos CreditAttribution: ParisLiakos commentedis there another way to do #1862202-172: Objectify the language system without putting the full namespace there?
not even the current namespace of the class is allowed:(
also other use statements in your class are not imported, which used to
Edit opened #2097585: Allow plugin managers to register namespaces to the annotation reader for this
Comment #24.0
ParisLiakos CreditAttribution: ParisLiakos commentedblub
Comment #25
webchickThis has a change notice, so I think we're good here?
Comment #26
webchickComment #28
xjmComment #29
klausiThis is currently being discussed to be reverted as IDEs such as PHPStorm give you useful hints when the use statement is there, see #2689243: Import classes used in annotations.
Comment #30
yonailo CreditAttribution: yonailo as a volunteer commented