Problem/Motivation
In the past (before we used DefaultPluginManager directly for ViewsHandlerManager, when this used to be done automatically I think?!) we had hooks invoked to handler definitions as well as standard plugins. The plugins still work ok but handlers do not get a 'views_handlers_TYPE' alter hook invoked. This is problematic.
Proposed resolution
Make sure this is invoked by fixing the implementation, utilising the DefaultPluginManager functionality
Remaining tasks
User interface changes
None
API changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | interdiff-2341385-18.txt | 6.22 KB | damiankloip |
| #18 | 2341385-18.patch | 5.85 KB | damiankloip |
Comments
Comment #1
dawehnerAWESOME a unit test!
Let's add a @coversDefaultClass
Comment #2
damiankloip commentedYep, covers added!
Comment #3
dawehnerAwesome!
Comment #5
damiankloip commentedComment #6
catchWhere's the hook documented in views.api.php?
Comment #7
webchickComment #8
damiankloip commentedGood point. Added to views.api.php
Comment #9
xjmWould views_HANDLER_TYPE_handlers_alter() be a better hook name than views_handlers_HANDLER_TYPE_alter()? Because what we're altering is handlers.
What's not clear to me is whether the handler list for each hook is limited to the handlers for that type, or what its array structure is or where I can find it in the API.
The list of all handler types from
Views::getHandlerTypes(): field, argument, sort, filter, relationship, header, footer, empty. (Header, footer, and empty are all area handlers.) So all of them are covered. Cool.What if we add an additional handler type in the future? The handler type would automatically be altered, but the specific alter hook would be undocumented.
Would it make sense to document it only once, along the lines of hook_field_widget_WIDGET_TYPE_form_alter()? We'd need a more detailed code example and explanation (see below).
It's a bit confusing to have this example for all six of the hooks. To the reader, the "title handler class" doesn't seem to have anything to do with altering the list of sort handlers or whichever. Can we come up with a better example, and explain how which handler type is being altered plays a role?
Comment #10
xjmRe: #9 point 3, OTOH, the list of field widget types is a lot more in flux than views handler types, since AFAIK contrib cannot add a handler type (can it?), just handlers of one of the existing types. (
Views::getHandlerTypes()is an unalterable static for a protected class property that is not touched anywhere else in the class; you'd have to overrideViewsorViewExecutableto change it as far as I can tell.)So maybe the specific hooks are good.
Comment #11
xjmI should also note that I'm not sure about #9 point 1; just raising the question.
Comment #12
dawehnerWell, yeah both would work. Plugins also do hook_views_plugins_$plugintype_alter, so I think this is fine, unless you want to change both instances.
Well it is limited, not sure whether this is worth to mention. I think this is what you expect it to be.
I don't see why, this is pretty much all you can do here, replace the class. There isn't more metadata worth to change. It also doesn't make sense to have some if() as you can just change them globally anyway.
Comment #13
xjmWell clearly it's not, because I had no idea reading the list. :) And where can I learn more about the structure of the list? Is there a method that returns it?
The problem is that reading the docs, I actually have no idea how I'd use the hooks. Maybe you could describe an example of how I'd use it, and I can help incoprorate it into Damian's docs?
Comment #14
dawehnerJust to ensure we know what we talk about here: The only usecase is to replace an existing handler class, I can't think of any other one.
In the new handler class you do some arbitrary other logic, for example change the way how the title is rendered (in case of field handlers)
Comment #15
olli commentedThis needs to adapt views_hook_info() which currently defines these as hook_views_plugins_HANDLER_TYPE_alter. OTOH I wouldn't mind having hook_views_plugins_*_alter for views handler plugins.
Comment #16
catchI think we should remove dynamic hooks from views_hook_info() for now. Dynamic hooks really shouldn't be in there - it's supposed to be for lazy loading of hook code (which is questionable in 8.x anyway) as well as just organisation, and doing work to identify the code to be lazy loaded quickly cancels any benefits out.
Comment #17
dawehnerI agree with olli, let's use hook_views_plugins_$type_alter() as we already define it.
I disagree because it makes your code a bit less easy to read.
hook_views_dataandhook_views_plugins_$type_alter()work together, so having them inone place helps quite a bit in terms of readabilty. At least for the later hook there is though indeed no point in lazyloading, the amount of extra code is basically zero.
Comment #18
damiankloip commentedSure, I am ok with that. Whatever really, as long as we have a hook :)
I think if we want to remove anything from views_hook_info() should should punt that to another issue?
Comment #19
dawehnerdamian++
Comment #20
alexpottCommitted 695afed and pushed to 8.0.x. Thanks!
Fixed minor spelling mistake on commit.
Comment #22
damiankloip commentedHA. Thanks Alex!
Comment #23
dawehnerI was fine with using german here :)