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.
Problem/Motivation
When using annotated classes, it is easy for the definition to be converted to an object. See \Drupal\Core\Entity\Annotation\EntityType::get()
for an example.
However, if using another form of discovery like YAML, there is no means to convert the array to an object.
Proposed resolution
Introduce a discovery decorator that transforms arrays into a specified classed definition object.
Remaining tasks
User interface changes
N/A
API changes
API addition (not really even, just a new cool thing to use?)
Data model changes
N/A
Comment | File | Size | Author |
---|---|---|---|
#17 | 2822752-plugin-17-interdiff-from-2.txt | 6.08 KB | tim.plunkett |
#16 | 2822752-plugin-16.patch | 6.29 KB | tim.plunkett |
#16 | 2822752-plugin-16-interdiff.txt | 2.85 KB | tim.plunkett |
#15 | 2822752-plugin-15.patch | 6.17 KB | tim.plunkett |
#15 | 2822752-plugin-15-interdiff.txt | 4.61 KB | tim.plunkett |
Comments
Comment #2
tim.plunkettComment #3
tim.plunkettBump
Comment #4
jibranThis is straight forward. Where else in the core can we use it?
Comment #5
tim.plunkettI don't believe we can use it any other places without some very ugly ArrayAccess BC, and not sure we want that.
But IMO, any new plugin type in contrib or core should be using object-based plugin definitions.
Comment #7
tim.plunkettComment #8
EclipseGc CreditAttribution: EclipseGc commented++
Comment #9
xjmNote that issues like this should be targeted against 8.4.x, but can be considered for backport once they are committed to that branch. See the updated alpha release policy. Thanks!
Comment #10
alexpottWe should have an explicit test of this functionality outside of the experimental layout module then. Just in case we remove the experimental module (unlikely though that is).
Comment #11
effulgentsia CreditAttribution: effulgentsia at Acquia commentedAlso, since this is a move from @internal to not, we should review the entire class, not just the diff.
The code being moved includes this:
AnnotationInterface
needs to be in the docs of the constructor. Either in addition to or instead of the docs of the protected property.AnnotationInterface
doesn't extendPluginDefinitionInterface
or its companions from the other recent issues. Wouldn't that then cause problems? Especially since the default inDefaultPluginManager::__construct()
isDrupal\Component\Annotation\Plugin
, which also doesn't implement those interfaces. So we might need docs here saying there's in practice additional expectations for$plugin_definition_annotation_name
, and we might want to consider changing DefaultPluginManager's default value to something that meets those expectations.Comment #12
tim.plunkett#10: will do
#11:
1) sure
2) Annotation != Definition
All of our annotations implement AnnotationInterface.
The return value of
\Drupal\Component\Annotation\AnnotationInterface::get()
is a definition. This is either an array or PluginDefinitionInterface.I'm not sure what you want changed here.
Comment #13
tim.plunkettComment #14
effulgentsia CreditAttribution: effulgentsia at Acquia commentedThese two comments are contradictory. If all that's required is that the annotation class implements
AnnotationInterface
, then its get() method might return either an array or an object. So the statement at the top thatObjectDefinitionDiscoveryDecorator
"ensures that all array-based definitions are converted to objects" is incorrect.Comment #15
tim.plunkettAgreed that it is confusing.
@effulgentsia and I discussed this at length, and he proposed a new name: AnnotationBridgeDecorator
I think the new name and the rewording of the docs is a big improvement.
Comment #16
tim.plunkett@effulgentsia also suggested moving the namespace to match \Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery.
Comment #17
tim.plunkettInterdiff since #2, last time RTBC.
Comment #18
jibranThis is a task to move the internal api to public so this makes it a feature request and I think we should have a change record for this 'feature request' so that core and contrib can use it as mentioned in #5.
Let's add a comment that both discovers are converted to object.
The code looks good. The test looks good. My comments are just minor improvements, can be ignored if someone disagrees, and not commit blocker so RTBC.
Comment #19
effulgentsia CreditAttribution: effulgentsia at Acquia commentedThanks, @jibran! Ticking credit box for review.
Comment #22
effulgentsia CreditAttribution: effulgentsia at Acquia commentedPushed to 8.4.x. Cherry picked to 8.3.x, because it's low disruption and provides a great pattern by which contrib plugin managers can use object definitions with YAML discovery without each such contrib module creating their own solution, like
LayoutPluginManager
had to do prior to this issue.Per #18, a CR to inform people of this addition (or maybe a single consolidated CR for all the improvements to using object definitions) would be great. As would be the follow-up to add a comment within the test coverage.