In order to better define what it means to be a views handler, we can stop using the generic @Plugin in favor of a specific @ViewsHandler.
Handlers are pretty straightforward, and actually don't need anything other than their ID.
This will also let us document the annotation keys better (even more important for non-handlers, I'll open that issue tomorrow).
Now that services are in YAML, we can individually swap out each handler type as we go. I've converted relationships, since there are so few of them.
This is mostly @msonnabaum's idea, but I happen to agree with him.
This will also prevent people from tacking on arbitrary data to the annotation.
Comment | File | Size | Author |
---|---|---|---|
#24 | vdc-1965164-24.patch | 126.25 KB | tim.plunkett |
#24 | essential-changes-with-one-example-do-not-test.patch | 6.97 KB | tim.plunkett |
#24 | interdiff.txt | 825 bytes | tim.plunkett |
#22 | vdc-1965164-22.patch | 126.22 KB | tim.plunkett |
#22 | interdiff.txt | 24.45 KB | tim.plunkett |
Comments
Comment #1
dawehnerOne problem I do have with this is the fact, that a random developer can no longer apply exactly what he has learned so far on plugins,
and write @Plugin etc. Does this mean that each plugin type has it's own class here?
What would happen if they actually want to add additional metadata. For example :
Would you need to specify a new annotation class, or use @Plugin() again?
If we think this is a good idea I think we should name it ViewsPlugin() because the main reason why people get confused about handlers in the firstplace is that we call them different. If people understand the plugins concept, having another name feels really counterproductive.
Comment #2
dawehnerHandlers are plugins, that's it. Noone should stop you from using additional metadata, if you think it's a good idea.
Comment #3
tim.plunkettViews is the owner of the API, and as the consumer should define up front what metadata is appropriate for each plugin type. Any of that information is not metadata, and is only useful with an instantiated object.
And there is still an important distinction between a handler and a plugin (in the views sense), even the base class points this out.
Comment #4
dawehnerGood point, so I will open a follow up to get this cleaned up now.
Please let avoid that different naming in the first place. A dev don't need the name "handler" to know. Filter is just another plugin type provided by views.
I guess with moving to yml files we don't need this anyway.
Comment #5
tim.plunkettYeah, we're not switching this to YAML.
I figured out how to remove the "id=" bit, this is much nicer.
Left to do are arguments and fields. There are 33 argument handlers and 70 field handlers... So I'll wait for another review first :)
Only non-handlers need other metadata, so this enforces that it only has an ID.
Comment #6
chx CreditAttribution: chx commentedwe definitely need no stinkin' comments on why do we store the ID in $value. No.
Comment #8
tim.plunkettOkay, after further discussion, we realized that an annotation that only has a plugin ID is generically useful.
So I've moved it to Component, as PluginID. When the namespaces fix went in for managers, we no longer needed the 'module' key, so those that use just id and module can switch to this as well.
Converted Join, argument will have to wait on #1965842: Move date argument annotations to properties
I added a comment per chx's request.
Comment #9
damiankloip CreditAttribution: damiankloip commented@tim, I was going to ask about the module key. What issue was that?
Comment #10
xjmComment #11
tim.plunkettIt was #1836008: Remove drupal_classloader() use in Drupal\Core\AnnotatedClassDiscovery. Those were added in to work around simpletest loading all namespaces, and plugin discovery using the global namespace list
Comment #12
dawehnerI'm wondering whether we should still have the module information somewhere stored. I guess some layer could add them in later.
Now that we have the @PluginID one, can't we now inherit from the Core/ one?, as we don't need the constructor anymore? I don't see an advantage to not reuse the other one.
Can't we just use function (&$definition, $key) use ($type)?
Can't we still add this as default value on the manager?
I think, that we can't know whether someone wants to use the alter decorator, etc., which then at the end of the day would all fallback to use just the ViewsPluginManager as it is.
Comment #13
xjmSee also: #1825896: Add module owner to plugin data on handlers
Comment #15
damiankloip CreditAttribution: damiankloip commentedNice. I still like the idea of us storing the plugin module.
Comment #16
tim.plunkettYes, handlers don't currently need to know about the module. If they do, we should bake that into the Discovery class, not force plugin implementors to specify it.
We can't use the core one, since we have to set Drupal\Component\Annotation\PluginID as the $pluginDefinitionAnnotationName (see the Drupal\Component\Plugin\Discovery\AnnotatedClassDiscovery::__construct()
array_walk specifically has a third param, and I don't think you can do
use ($this->type)
with the property.I've moved plugin_type here, since it skips the entire layer of ProcessDecorator, call_user_func_array(), and NestedArray::mergeDeep().
The alter decorator isn't needed for handlers, since only the ID is checked. hook_views_data()/hook_views_data_alter() is where that should take place.
Fixed the $annotation_namespaces.
Comment #17
msonnabaum CreditAttribution: msonnabaum commentedI like @PluginID ok. A single annotation is nicer than a hash when possible.
Patch looks pretty good, although I think the array_walk is not necessary. It's less readable than foreach in this context since you have to pass around the reference.
One thing I wanted to address:
For me, this is the goal. Developers should know that Entity types require an annotation and Views handlers require an annotation, but it's not necessary to know that they are using the Plugin system. Plugins are very difficult to understand in the abstract, so I think the best possible DX we can offer is to treat them like an implementation detail.
Comment #19
tim.plunkettComment #20
tim.plunkettConverting arguments is blocked on #1965842: Move date argument annotations to properties.
Here's fields.
Comment #21
dawehnerLooks fine, let's wait for arguments.
Comment #22
tim.plunkettAwesome, that went in.
So this is "done" now, needs some full reviews.
Comment #23
dawehnerIf thinks this is RTBC beside this small nitpick.
Defaults to array()
Comment #24
tim.plunkettOkay. I've also attached a patch with all but one conversion removed, to help highlight the real changes.
Comment #25
dawehnerAwesome!
Comment #26
tim.plunkettThis touches every views handler, is tedious, and is not easily automated. So, please don't break it.
Comment #28
tim.plunkett#24: vdc-1965164-24.patch queued for re-testing.
Comment #29
tim.plunkettBot--
Comment #30
xjmComment #31
alexpottCommitted ee1c53e and pushed to 8.x. Thanks!
Comment #32
xjmYAY!
Comment #33
andypostPlease update issue summary or file change notice to how to use it now!
Comment #34
xjmYeah, this actually needs both a core change notice (for the core API addition) and a views one. (The views one being added on top of the major views plugin conversion one we haven't written yet.) ;)
Comment #35
tim.plunkettExpanded http://drupal.org/node/1704454 to include PluginID.