3 namespace Drupal\Core\Cache\Context;
5 use Drupal\Core\Cache\CacheableMetadata;
6 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
7 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
10 * Defines the MenuActiveTrailsCacheContext service.
12 * This class is container-aware to avoid initializing the 'menu.active_trails'
13 * service (and its dependencies) when it is not necessary.
15 class MenuActiveTrailsCacheContext implements CalculatedCacheContextInterface, ContainerAwareInterface {
17 use ContainerAwareTrait;
22 public static function getLabel() {
23 return t("Active menu trail");
29 public function getContext($menu_name = NULL) {
31 throw new \LogicException('No menu name provided for menu.active_trails cache context.');
34 $active_trail = $this->container->get('menu.active_trail')
35 ->getActiveTrailIds($menu_name);
36 return 'menu_trail.' . $menu_name . '|' . implode('|', $active_trail);
42 public function getCacheableMetadata($menu_name = NULL) {
44 throw new \LogicException('No menu name provided for menu.active_trails cache context.');
46 $cacheable_metadata = new CacheableMetadata();
47 return $cacheable_metadata->setCacheTags(["config:system.menu.$menu_name"]);