Problem/Motivation
We currently have 3 discovery mechanisms and 4 decorators in core. All but one decorators implement __call()
in the same way, and all but one discovery mechanisms and decorators implement getDefinition()
in the same way. Both of these implementations can be considered generic implementations that most discovery mechanisms and decorators in contrib will likely implement as well.
Proposed resolution
Create a DiscoveryBase
which implements getDefinition()
and a DiscoveryDecoratorBase
which extends DiscoveryBase
and implements __call()
. In core alone this patch has a negative diffstat.
Remaining tasks
Review patch.
User interface changes
None.
API changes
None. There is no "We have a new Plugin API" change notice. If we ever create one, we should mention the new base classes.
Comment | File | Size | Author |
---|---|---|---|
#11 | 1809200-11.discovery-base.patch | 15.39 KB | tstoeckler |
#6 | 1809200-5-plugins-discovery-base.patch | 11.41 KB | tstoeckler |
#6 | 1809200-1-5-interdiff-do-not-test.patch | 3.59 KB | tstoeckler |
#1 | 1809200-1-plugin-discovery-base.patch | 9.72 KB | tstoeckler |
Comments
Comment #1
tstoecklerHere's the patch.
Comment #2
sunLooks good to me and seems to make sense.
There doesn't seem to be a difference in terms of PHP class discovery/loading either; the interface is replaced with a base class, so just a different lookup.
I only have a stupid nitpick:
Apparently, there's supposed to be a blank line before the closing curly brace of a class definition.
Comment #4
tstoecklerRe #2: I think that *should* be a standard, but it currently isn't. See http://drupal.org/node/608152
Since it's completely unrelated, I'll take it out of the patch, though. Better patch coming up in a minute.
Comment #5
andypostIt breaks a lot of things, so better leave this postponed til feature freez
Comment #6
tstoecklerWow, I managed to massively mess that up...
This one should work.
I also found LegacyDiscoveryDecorator in field.module.
Comment #7
tim.plunkettI agree with @andypost, this is a nice clean-up that should probably wait, it will break a lot of the issues that are using this code.
Comment #8
tstoecklerHmm... I guess there's nothing that inherently speaks against doing this after feature-freeze, but can you explain what exactly would be touched by this? Any code sub-classing any of the existing classes is not affected. I.e. only patches that actually change/refactor the current discovery mechanisms and decorators would need to be rerolled. I'm not aware of any of those, so. Maybe I'm missing something.
Comment #9
tim.plunkettOh, hmm, DiscoveryInterface is still able to be used in typehinting...
I take it back! Carry on.
Comment #10
tim.plunkettAfter writing my own DiscoveryDecorator tonight, this makes things much much clearer.
Comment #11
tstoecklerThis needed quite a re-roll.
Forgot to add the diffstat to the patch, but by now it's +71 -138, so not bad I guess. :-)
Comment #12
tim.plunkettI guess they ignored this issue and did #2026769: Simplify DerivativeInterface implementations by refactoring duplicated code to a base class instead.
Comment #12.0
tim.plunkettUpdated issue summary.