Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Cache / Context / MenuActiveTrailsCacheContext.php
1 <?php
2
3 namespace Drupal\Core\Cache\Context;
4
5 use Drupal\Core\Cache\CacheableMetadata;
6 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
7 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
8
9 /**
10  * Defines the MenuActiveTrailsCacheContext service.
11  *
12  * This class is container-aware to avoid initializing the 'menu.active_trails'
13  * service (and its dependencies) when it is not necessary.
14  */
15 class MenuActiveTrailsCacheContext implements CalculatedCacheContextInterface, ContainerAwareInterface {
16
17   use ContainerAwareTrait;
18
19   /**
20    * {@inheritdoc}
21    */
22   public static function getLabel() {
23     return t("Active menu trail");
24   }
25
26   /**
27    * {@inheritdoc}
28    */
29   public function getContext($menu_name = NULL) {
30     if (!$menu_name) {
31       throw new \LogicException('No menu name provided for menu.active_trails cache context.');
32     }
33
34     $active_trail = $this->container->get('menu.active_trail')
35       ->getActiveTrailIds($menu_name);
36     return 'menu_trail.' . $menu_name . '|' . implode('|', $active_trail);
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function getCacheableMetadata($menu_name = NULL) {
43     if (!$menu_name) {
44       throw new \LogicException('No menu name provided for menu.active_trails cache context.');
45     }
46     $cacheable_metadata = new CacheableMetadata();
47     return $cacheable_metadata->setCacheTags(["config:system.menu.$menu_name"]);
48   }
49
50 }