Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
routing system
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
7 Jun 2014 at 22:26 UTC
Updated:
29 Jul 2014 at 23:40 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
Crell commentedWow, it worked! :-)
I checked again and it doesn't look like any other base classes are using this pattern, so this is complete. Yay, easy conversions! Please review/RTBC.
Comment #2
dawehnerLooks valid.
Comment #3
vijaycs85Looks like we got different visibility and now it is protected? are we sure, no need for tests?
Only public method in this trait is url(), but name is LinkGeneratorTrait and not UrLGeneratorTrait?
Comment #4
Crell commentedIt doesn't make sense to me to have separate traits for l() and url() since they are closely related. LinkAndUrlGeneratorsTrait seems like a silly name, so I went with the one with fewer acronyms. :-)
Re visibility, we should normalize that. StringTranslationTrait has the "useful" methods protected, and the override setters public. LinkGeneratorTrait should do the same. I'll see about fixing that tonight unless someone wants to beat me to it. (Please do!)
Comment #5
Crell commentedFixed the protected/public issue and added a docblock to the trait itself.
Comment #6
vijaycs85Thanks again @Crell. It looks good to me. +1 to RTBC. Created #2283385: Remove BreadcrumbBuilderBase as followup to remove the base class.
Comment #7
Crell commentedCan you mark it back to RTBC then? :-)
Comment #8
vijaycs85Ok then :)
Comment #10
znerol commentedI'm working on maintenance mode over at #2288665: Remove _maintenance request attribute and replace it with a maintenance mode service and #2288911: Use route name instead of system path in user maintenance mode subscriber. It looks like the various
MaintenanceModeSubscribermight profit from an url-generator trait. In those classes it would be very helpful to also have theContainerBase::redirect()method in the trait. On the other handl()is completely unnecessary there.A quick grep through the code base excluding yml, api.php, vendor, tests, interfaces and
Drupal.phpcontaining procedural wrappers turns up the following result:LinkGeneratoris mentioned in 3 files,UrlGeneratorin 29 files. Only two files are common (ControllerBase.phpandLinkGenerator.php).This raises the following questions:
ContainerBase::redirect()method is moved into the trait also?Comment #11
Crell commentedWhether kernel event listeners are application or not: Hm. There was a lengthy discussion about that a while back that didn't come to a resolution. effulgentsia did an audit of listeners we had at the time. This isn't really the right place to re-have it, though.
redirect() belongs only in the Controller, as you have to return a redirect object; it's not just for formatting a string. Triggering a redirect in most non-Controller places is a code smell. From an event listener specifically there's nowhere to return it, except maybe setting a Response object on the event. That's sufficiently rare that I don't think the shortcut is needed, certainly not with the SL cost it incurs.
We could split it out I guess; I just didn't see much cause to do so. But... I guess they're wrapping 2 different services, so if we want one trait per wrapped service... Meh, I guess so.
Comment #12
Crell commentedSigh. Broken by the serialization trait. Rerolled.
Also went ahead and split the trait in two. No other changes. Let's see if I got the usages right...
Comment #14
Crell commentedYep, I forgot one.
Comment #15
effulgentsia commentedPatch looks good. Just a couple questions:
When we added the StringTranslationTrait, we renamed the service getter method from translationManager() to getStringTranslation(). Along the same lines, should we prefix a "get" onto these two?
This relates to #10.1 and the desire to use this trait within an event subscriber in #2288911: Use route name instead of system path in user maintenance mode subscriber. I agree that so long as the event subscriber is a service, which they all are pending #2023613: Move event registration from services.yml to events.yml, it should use constructor injection rather than a fallback to \Drupal::. However, couldn't it still use the trait along with CI (and e.g., ensure that by changing the setter to private)? If so, should we refine this comment to explain that?
Comment #16
Crell commented15.1: Meh, renamed. Although that led me to discover (courtesy of PHPStorm's refactoring command) a whole bunch of places that were accessing that method rather than using url() and l() and such directly. I fixed most of those. The only ones I left were 2 path-based lookups (which are bad anyway) 1) One that had a @todo on it for an issue that is not yet in (I didn't want to mess up a reroll for someone else) and 2) a path-based lookup for a node link, the route name for which is about to change via #2278567: Standardize node route names by relationship so I wanted to avoid the collission. That's an easy change for later.
15.2: I don't want to structure the comment around things that may or may not happen. It's already decently vague in saying "only use this if you're not in the container so constructor injection is annoyingly hard". ContainerInjectionInterface is just the most common example of that. As Tim pointed out to me the other day in chat, we have 4(!) static::create()-based interfaces. (That should get condensed...) The comment shouldn't tie deeply into the rest of the system architecture, just give a suggestion for when to use it.
Comment #17
sunPatch contains some coding style issues, but we can polish coding style at any later point in time.
Comment #18
alexpottCan we get an issue to remove
BreadcrumbBuilderBaseCommitted c072353 and pushed to 8.x. Thanks!
Comment #20
vijaycs85here it is #2283385: Remove BreadcrumbBuilderBase