You are here

class RouteAdminCacheContext in Responsive Theme Preview 8

Defines the RouteCacheContext service for "per admin route" caching.

Cache context ID: 'route.is_admin'.

Hierarchy

Expanded class hierarchy of RouteAdminCacheContext

1 string reference to 'RouteAdminCacheContext'
responsive_preview.services.yml in ./responsive_preview.services.yml
responsive_preview.services.yml
1 service uses RouteAdminCacheContext
cache_context.route.is_admin in ./responsive_preview.services.yml
Drupal\responsive_preview\Cache\RouteAdminCacheContext

File

src/Cache/RouteAdminCacheContext.php, line 14

Namespace

Drupal\responsive_preview\Cache
View source
class RouteAdminCacheContext implements CacheContextInterface {

  /**
   * The route admin context service.
   *
   * @var \Drupal\Core\Routing\AdminContext
   */
  protected $routeAdminContext;

  /**
   * Constructs a new RouteCacheContext class.
   *
   * @param \Drupal\Core\Routing\AdminContext $route_admin_context
   *   The route admin context service.
   */
  public function __construct(AdminContext $route_admin_context) {
    $this->routeAdminContext = $route_admin_context;
  }

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return t('Route is admin');
  }

  /**
   * {@inheritdoc}
   */
  public function getContext() {
    return $this->routeAdminContext
      ->isAdminRoute() ? '1' : '0';
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() {
    return new CacheableMetadata();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteAdminCacheContext::$routeAdminContext protected property The route admin context service.
RouteAdminCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
RouteAdminCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
RouteAdminCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
RouteAdminCacheContext::__construct public function Constructs a new RouteCacheContext class.