Problem/Motivation
Currently breadcrumb builders return an array of links using l(). There are a couple of problems with that:
- Due to HTML = TRUE in the path based breadcrumb builder it is potentially insecure
- Theming support is not optimal, currently breacrumbs are just printed out
- Altering is somehow is difficul, given that it is already a link
- You always need to use the link generator in order to do anything useful
Proposed resolution
Return an array of link objects, which contain a title and a URL.
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#33 | 2314599-33.patch | 1.03 KB | andypost |
#29 | interdiff.txt | 14.18 KB | Crell |
#29 | 2314599-breadcrumb-links.patch | 35.2 KB | Crell |
#17 | breadcrumb_link-2314599-17.patch | 35.01 KB | dawehner |
#17 | interdiff.txt | 604 bytes | dawehner |
Comments
Comment #1
dawehnerHere is a start of the functionality.
Comment #3
dawehnerSome fixes for various tests.
Comment #5
dawehnerComment #7
dawehnerFixed the failure.
Comment #8
Crell CreditAttribution: Crell commentedOverall I love this change and I'm sorry we didn't do it sooner. That said, some comments. None are fatal with the possible exception of the __toString() method:
Out of curiosity, why [] for the inner arrays but not outer? Seems odd.
Are we sure there's no more appropriate namespace? I'm tempted to say Drupal\Core\Page as this is basically HtmlAElement, but I don't want that to become too much of a dumping ground.
Pursuant to the previous comment, should this be called LinkElement? (I'm OK with no, but that should be a conscious decision.)
Why the ellipsis at the end?
The docblock for this method scares me, but it's the same as we're using for the code that this is replacing so I'll hold my nose for now. :-(
Needs @return with type.
*cries at the call to \Drupal inside a class*
We really need to stop doing that. :-(
Why use the constructor directly here instead of a factory method?
I love this hunk on principle. :-)
Comment #9
dawehnerWell, yeah, let's not start using [] in random issues.
I decided to put it into the same namespace as the URL object. If we have a proper URL namespace we can move the Link into the same one. No, this is not about the element (HTML) itself, it is also about holding the information of a link together which is a URL + text.
There is a small semantic difference, given that one day maybe someone comes up with other ways to render that information.
No special reason, removed that.
We could also switch the constructor: use these parameters in the constructor and have a dedicated createFromUrl() but then the semantic information, see above, is wrong.
Okay sure. Let's add a method on the link generator which can convert a link to a string. This makes more sense anyway.
Because this time we have a Url object available, do you want to have a createFromUrl as well? This feels a lit pointless to be honest.
Yeah, totally.
Comment #10
Crell CreditAttribution: Crell commentedI would have gone the other direction, as I find short-array-syntax much easier to read now after working with it for a while. :-)
Well, as is it feels inconsistent. Sometimes you use "new", sometimes a static factory. Even if one of the static factories is trivial it feels like it would be more consistent to always get a link from a static factory. (And of course we can add more later if we find a reason to do so.) I won't block the issue on that, but it seems like a second static factory would be better DX.
Oh, I like.
Comment #11
dawehnerThere is nothing different to how Url() works atm.
So RTBC?
Comment #12
Crell CreditAttribution: Crell commentedNo one in the WSCCI meeting today felt like chiming in, so I'll RTBC it. :-)
Comment #13
star-szrI like this, thanks @dawehner and @Crell for reviewing!
Comment #14
dawehnerComment #15
dawehner.
Comment #16
alexpottQuick review.
missing @return
Comment #17
dawehnerOh you are right.
Comment #18
andypostThe mixed creation of new Link object seems better to unify.
Probably better get rid of static method and use
new Link($text, new Url(...))
all overbreadcrumb is a internal variable populated in preprocess
Comment #19
m1r1k CreditAttribution: m1r1k commentedI don't like the idea at all, because we're turning just simplified Breadcrumb API that was prepared for themers and sitebuilders via contrib modules but not only for backend stuff. All this patch makes almost imposible to add custom class to particular item, set last item as pure text (common thing in breadcrumbs), we can't alter item in any way.
Like it, may be move to the separate patch and use it somewhere else in the core?
Lets move this logic to particular Builder instance. Because breadcrumbs is list of html items (secure or not, link or divs) but not escaped by default list of links.
So lets use renderable array, because current patch doesn't bring to mich space for themers
Now it''s not a link yet but will definitely be and we can't do anything :)
Comment #20
dawehnerThank you for the review.
As told you already. I would argue that pure link strings aren't alterable either.
I could imagine that other places could be for example when views generates its links.
I wonder whether we could put this logic onto the link object, much like we store on the page object whether a title is safe or not.
Well, I would argue that having the generated HTML inside the template is actually a win. They not longer have to use preprocess and other stuff,
to add classes to the tag for example
Unless we have setters on there.
Comment #21
Crell CreditAttribution: Crell commenteddawehner and I discussed this during today's WSCCI meeting. Conclusion:
* Whether or not to show the current page title is NOT the responsibility of a particular builder. The builders are responsible for per-path or per-route or per-content type distinction. Showing the current page or not is a site-level decision.
* Thus, the correct place to make that decision is... in the breadcrumb block. The builders MUST NOT handle the current page, period. The block can/should be configurable to tack on the current page title for display. That's a display-level decision.
* The block currently does not, therefore there is no regression here that it still doesn't. The builders are still responsible for exactly what they should be responsible for.
* Thus, someone please file a follow-up to allow the breadcrumb block to be configured to show the current page title or not. :-) This issue is not blocked by that.
Comment #22
dawehnerComment #23
Crell CreditAttribution: Crell commentedI think we're back to RTBC then.
Comment #25
star-szrRerolled, just a small conflict with #2291833: Standardize taxonomy term entity route names.
Comment #26
webchickWow, this looks insanely awesome. Couple of small things, and then this is good to go.
Can we shorten to just createFromRoute? It's confusing because neither $text nor $route_name are actually arrays, and we can just type-hint route_parameters / options to arrays to indicate what data type they expect (so let's do that).
Why getText/setText, but only getUrl?
Yay!
Yay!!!!
Comment #27
aspilicious CreditAttribution: aspilicious commentedif we change #breadcrumbs to #links, shouldn't we change {% for item in breadcrumb %} to {% for item in links %} ???
Comment #28
aspilicious CreditAttribution: aspilicious commentedOh never mind "function template_preprocess_breadcrumb(&$variables)"...
Comment #29
Crell CreditAttribution: Crell commentedChanges per #26. I don't know if there was a reason setUrl was excluded but the parallelism makes sense to me so...
Interdiff only looks big because it's a lot of renaming, courtesy PHPStorm.
Comment #30
webchickLooks good!
Comment #31
webchickGreat. Committed and pushed to 8.x. Thanks!
Comment #33
andypostit was fixed but commited a wrong - there's no breadcrumb argument
Comment #34
dawehner@webchick
What happened with all the committ messages?
@andypost I generally prefer to just open quick dedicated follow ups, meh
Comment #36
webchick"What happened with all the committ messages?" Sorry? I don't quite parse that. :)
Committed and pushed #33 to 8.x as well.
Comment #37
dawehner@webchick
It seems to be that dreditor is kinda broken atm:
It should be kinda the other way round. Just noticed.
Comment #38
star-szr@dawehner I noticed that too. It's a Safari-specific Dreditor bug. See https://github.com/dreditor/dreditor/issues/226, I will try to fix it this week.
Comment #40
tim.plunkettUnfortunately, this broke the suggestion hook_system_breadcrumb_alter makes. No idea why it would FORCE you to have every array value to be a Drupal\Core\Link object.
Also, why is breadcrumb.html.twig completely bypassing the LinkGenerator, and therefore ignoring any options passed to a link?
Comment #41
tim.plunkettSee #2345801: template_preprocess_breadcrumb() assumes all breadcrumbs are \Drupal\Core\Link objects