Hello,
Since some projects, I heard some of my colleagues complaining about the difficulty to alter links displayed in the breadcrumb.
It comes from the fact the breadcrumb is built through the "menu_get_active_breadcrumb()" function that retrieves the breadcrumb and returns directly them as hyperlinks in the array that will be consumed as variable in the "theme_breadcrumb()" call of "template_process_page()".
In order to add an attribute a breadcrumb item, that obliges us either to parsing the string variable in order to inject it in the HTML or to regenerate each breadcrumb item in order to add it before render them as link.
In order to avoid this kind cumbersome process, IMO, "menu_get_active_breadcrumb()" should returns an array of keyed arrays. Each keyed array would contain data allowing creating the hyperlink displayed in the breadcrumb and could be "preprocessed" by any modules or themes if necessary.
It is what I propose in the attached patch.
In it, I also keep the old implementation in order to ensure the backward compatibility.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | change_breadcrumb_strings_into_array-2863108-11.patch | 6.94 KB | jyraya |
| #7 | change_breadcrumb_strings_into_array-2863108-7.patch | 6.04 KB | jyraya |
| #2 | change_breadcrumb_strings_into_array-2863108-1.patch | 5.85 KB | jyraya |
Comments
Comment #2
jyraya commentedComment #3
jyraya commentedComment #5
jyraya commentedOk. I see the problem I will try to fix ASAP.
Comment #6
jyraya commentedComment #7
jyraya commentedOk.
I change the backward compatibility strategy in the patch. All manual and automated tests are green.
Let's try this new patch.
Comment #8
jyraya commentedComment #10
polHi,
Very good initiative, this is what I do in a very similar way in Atomium, without keeping the backward compatibility.
One thing to say, once this is done, you could move the generation of the breadcrumb from the process to the preprocess then.
Good luck!
Comment #11
jyraya commentedLet's try again . I replace the overriding of the theme_breadcrump in garland by a hook_preprocess_breadcrumb().
That let me think about the backward compatibility for others custom or contrib themes that override the "themeBreadcrumb" function. Someone knows how to deal with this kind of situation?
Should we:
Any opinions are welcomed!
Comment #12
jyraya commentedOk. tests failing with PHP 7 but nothing related to the patch.
Concerning the your proposal Pol, I need to investigate this part because this comment in the template_process_page explains why it is in the process instead of the preprocess:
Comment #13
jyraya commentedComment #14
pol+1 for using this patch.
I'm already doing something similar in the Atomium theme.
Comment #15
David_Rothstein commentedComment #16
David_Rothstein commentedThis "separator" stuff is interesting but I don't see what it has to do with the rest of the patch.
Why is a new filter_xss() call being introduced here?