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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dgroene created an issue. See original summary.

dgroene’s picture

Patch attached.

ozin’s picture

Status: Active » Needs review
zipymonkey’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.15 KB

I added a space after the elseif but the patch works as advertised.

Ankush_03’s picture

Patch #4 Working fine for me.

  • ozin committed 0d0110a on 8.x-2.x authored by zipymonkey
    Issue #3094949 by dgroene, zipymonkey: Cache context does not account...
ozin’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.