Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently the path for the breadcrumb uses the path from the request context of the page; this works fine in a normal use case. Given that we are passing in the route match for the current request anyway could this be used?
This would also allow a breadcrumb to be used in the context of a search result or other view mode of the content by calling the build method with a route match for the request for the given page.
Comment | File | Size | Author |
---|---|---|---|
#12 | 2979021-12-use-route-match-for-breadcrumb-path.diff | 1.83 KB | andy_w |
| |||
#12 | interdiff.txt | 2.07 KB | andy_w |
Comments
Comment #2
andy_w CreditAttribution: andy_w at Numiko commentedComment #4
Greg BoggsHow does core do this?
Comment #5
andy_w CreditAttribution: andy_w at Numiko commentedCurrently in core the PathBasedBreadcrumbBuilder is also using the context rather than the route_match passed in, but this also seems to be incorrect behaviour, I've found an issue in the core queue (2884217) to resolve this in core.
Comment #6
andy_w CreditAttribution: andy_w at Numiko commentedComment #7
Greg BoggsThanks for finding this! I wish crumbs had their own core queue. Can we align our approach to cores a bit more closely maybe?
+ // Set request context from passed in $route_match if route is available.
+ $url = $route_match->getRouteObject() ? Url::fromRouteMatch($route_match) : NULL;
+ if ($url && $request = $this->getRequestForPath($url->toString(), [])) {
+ $route_match_context = new RequestContext();
+ $route_match_context->fromRequest($request);
+ $this->context = $route_match_context;
+ }
+
Comment #8
Greg BoggsComment #9
andy_w CreditAttribution: andy_w as a volunteer commentedYeah, I like the approach used in that ticket, I've rewritten the patch in line with the core queue patch and it seems to work exactly as expected.
Comment #10
andy_w CreditAttribution: andy_w as a volunteer commentedComment #12
andy_w CreditAttribution: andy_w as a volunteer and at Numiko commentedMoved the context replacer into its own function and caught the exception for invalid routes, so it just falls back to the current route.
Comment #13
andy_w CreditAttribution: andy_w as a volunteer and at Numiko commentedComment #14
cameron prince CreditAttribution: cameron prince as a volunteer commentedI've been using this patch on a few projects for several months now and it is working well.
Comment #16
diamondsea