We have new Symfony-based routes, and Views UI has a lot of routes.
Some of them, it turns out, are redundant.
The first step will be to just convert them, with as little changes as possible. This means loading views_ui/admin.inc in several methods, and decoupling later.
It also exposes some wonkiness in the routing system, which I will open a meta for soon, and link here.
#1889790: [Meta] Allow modules to register links for menus, breadcrumbs and tabs (if not with hook_menu) already outlines some of the problems, but hook_menu() still works for breadcrumbs, local actions, and local tasks (even default). However, contextual links do not seem to work at all.
Comment | File | Size | Author |
---|---|---|---|
#24 | vdc-1904854-24.patch | 47.95 KB | tim.plunkett |
#19 | vdc-1904854-19.patch | 47.95 KB | tim.plunkett |
#19 | interdiff.txt | 651 bytes | tim.plunkett |
#17 | vdc-1904854-17.patch | 48.7 KB | tim.plunkett |
#17 | interdiff.txt | 13.64 KB | tim.plunkett |
Comments
Comment #1
dawehnerThat's great so far!
So in general all this controllers should just provide glue code between the actual functionality and the route, so for example they should not contain logic like reportFields(). Instead use a proper object which get stuff injected and let the controller be containerAware, so the question is whether we really should couple all code now and decouple later.
Missing @return on all the functions.
Maybe we should explain what $views_ui could be, as it is announced as string here. Also the @param is wrong as it's $view_ui
If we have new code already, should we use the entity manager on this class now to get the form?
Why do we have to change the paths now, this seems to be a bit out of scope of this issue.
As written before, I don't think that the route controllers should be put into the controller all the time.
Maybe out of scope as well?
So in general all this controllers should just provide glue code between the actual functionality and the route, so for example they should not contain logic like reportFields(). Instead use a proper object which get stuff injected and let the controller be containeraware
Comment #2
tim.plunkettIf not on ViewsUIController, where should something like reportFields()? It is a page callback, it is not a form, it has no place to be. Why not here?
There is not much more to be decoupled, from the container perspective. Just stuff that is left in admin.inc that shouldn't be.
The docblocks were mostly copied, and were missing @return already. I'll add them.
Yep, $views_ui needs some docs. That and $view are all confusing until upcasting is in.
entity_get_form() contains all procedural functions, nothing that can be called from the entity manager :(
Those paths don't work, at all, in HEAD. I need to file a separate bug report for that.
We discussed this some in IRC, but we should prefer services over ContainerAware.
We only used ViewExecutable in those callbacks because that was what our menu loader did. But we don't ever need the executable, just the entity. So it's cleaner to just fix it.
Comment #3
dawehnerA new class called ViewsUIReportFields or something like that, see #1801356: Entity reference autocomplete using routes as example.
You want your stuff to be not only decoupled from the container but the functionality itself. Having a gigantic class is not that much better then page callbacks.
Regarding breaking, I'm sure there is an issue with tests etc. but it's too late to find that one.
Well yeah there are always a lot of things to fix, feel free to do what you think is best.
Comment #4
tim.plunkettI'm not sure about how best to break it up, I'll talk to Crell more.
Taxonomy autocomplete uses ContainerAware, that's not ideal.
Pushed up to http://drupalcode.org/sandbox/tim.plunkett/1698392.git/shortlog/refs/hea... because I couldn't decide whose sandbox to put it in.
e99b0e0 Replace MENU_NOT_FOUND with NotFoundHttpException.
18aa094 Move the admin.inc loading in the form controller so it works for AJAX.
d773865 Rename $arg1 and $arg2 to $type and $id.
e607978 Add linebreaks to make routes more readable.
e013801 Improve docs.
c06f121 Move views_ui_cache_load() onto the controller.
ed288fe Remove all traces of views_ui_cache_load().
Comment #6
dawehnerI totally agree that the main part should not be container aware, but why to pass the parts along?
Comment #7
tim.plunkettAbout half of the methods in ViewsUIController have module_load_include calls to views_ui/admin.inc, because some of the utility functions are called from deep within the form controller code.
They obviously need to be refactored, but that could be done in a dedicated issue, since it's not directly related to routes.
And, so far each module that has routes only has one controller. I can think of a couple ways to split this one up, but I think there are some more DIC services hidden in admin.inc, and I'd much rather split them up once that is done.
Also, this is not technically blocked on the upcasting issue. I'd like to see this get in pretty close to as-is, to keep the scope down an enable further progress.
Here is a new patch with all of the docs and coding standards brought up to date.
If we're okay with the above approach, then I'd like to get this in sooner rather than later.
Comment #8
dawehnerIt is getting better and better.
Missing @throws
We should for sure move that to another place as the controller should not be used in the actual code, so what about creating an todo?
Comment #9
Crell CreditAttribution: Crell commentedOverall I think this is a good first pass. There's plenty to clean up yet, but as Tim notes we should probably clean up the stuff this code is using first and iterate here. I'd be OK with moving forward with something more or less like this with the understanding that we will be revisiting it as time goes on and the dependent code here gets tidied up.
A few non-fatal comments:
Pedantic nitpick. $service_controller as a variable name is confusing. It took me 3 tries to figure out that you mean "the controller which was registered as a service." I thought at first you were referring to the service container, aka the DIC object.
Maybe just call it $controller, since once it's been retrieved that's all it really is? (As I said, pedantic nitpick.)
The request will be passed to the individual controller methods if you specify a parameter of Request $request. No need to put it in the constructor. Actually that might break things in some obscure places. :-)
Where to put stuff like this is an interesting question. :-) In Symfony, I believe a lot of it ends up as dedicated utility methods on the Entity Manager (roughly equivalent to our Storage Controller), which makes sense when you are editing code rather than configuring it.
I think for right now I'm fine with leaving this code here. Once we clean up other parts of the code, as Tim notes, it may become a lot more obvious what to do with it. That's generally true for page callback => controller conversion in general. We can do it iteratively.
Flagging this as one of the places to just pass in the request directly to the controller method.
Default values are not needed in controllers. The default values need to be specified by the route definition anyway.
Comment #10
tim.plunkettOkay, I responded to all of the feedback, thanks Crell.
Comment #12
tim.plunkettAh, that makes sense :)
Comment #13
Crell CreditAttribution: Crell commentedWorks for me. We can iterate from here.
Comment #14
dawehnerIn general this is impressive work!!
As a follow up we might could use Request::create() so we check the actual path as well, but yeah this is something which should be done over time.
Comment #15
tim.plunkett#12: vdc-1904854-12.patch queued for re-testing.
Comment #17
tim.plunkettRerolled for the ConfigEntityBase::status() changes and upcasting.
The only @todos now are the module_load_include, which I will open a follow-up for today.
Comment #19
tim.plunkettWhoops, missed one in the merge.
Comment #20
dawehnerWhy do we not provide a upcaster that converts it's directly to a ViewUI object, I guess this would be maybe a bit more complicated to do?
Comment #21
tim.plunkettI think that'd be reasonable to attempt if we didn't need the functionality in ViewPreviewFormController. Also, yes, it's much more complicated.
Plus, we're now relying on the upcasting to get us the View entity, which will still need, and I think this as an explicit method is okay.
Comment #22
dawehnerAfter a full reinstall this worked really fine. Tested quite different parts of the views edit UI, so I think this is finally ready to go
so we can iterate on top of it later.
Comment #23
dawehner.
Comment #24
tim.plunkettRerolled after #1843224: Convert Views Ajax commands to new Ajax API.
No changes, just the code I deleted had been tweaked.
Comment #25
webchickAwesome! It's lovely to see such a big module converted to use the new routing system. :)
Committed and pushed to 8.x. Thanks!