In my menu, when a page loads that matches a menu link, all of the parents of that link (ie- all of the items in the active trail) get an an "active" class and are displayed as underlined. However, the cache context, LinkItemContentActiveTrailsCacheContext, returns "link_item_content.inactive" for these parents because they are not THE active link- they are only being checked against getActiveLink(), not checked to see if they are in the active trail:
$active_trail_link = $this->container->get('menu.active_trail')
->getActiveLink($menu_name);
if ($active_trail_link && $active_trail_link->getDerivativeId() == $menu_link_id) {
return 'link_item_content.active.' . $menu_link_id;
}
else {
return 'link_item_content.inactive';
}
Therefore, when a page is loaded for which these parent links are not part of the active trail, they are still in the 'link_item_content.inactive' context and, when read from cache, still have the 'active' class and display as underlined.
Comment | File | Size | Author |
---|---|---|---|
#4 | add-active-trail-to-cache-context-3094949-4.patch | 1.15 KB | zipymonkey |
| |||
#2 | 3094949-2.patch | 1.16 KB | dgroene |
|
Comments
Comment #2
dgroene CreditAttribution: dgroene as a volunteer commentedPatch attached.
Comment #3
ozinComment #4
zipymonkey CreditAttribution: zipymonkey commentedI added a space after the
elseif
but the patch works as advertised.Comment #5
Ankush_03Patch #4 Working fine for me.
Comment #7
ozin