class RouteIsAdminCacheContext in Menu Per Role 8
Defines a cache context depending if the route is an admin route or not.
Hierarchy
- class \Drupal\menu_per_role\Cache\Context\RouteIsAdminCacheContext implements CacheContextInterface
Expanded class hierarchy of RouteIsAdminCacheContext
1 string reference to 'RouteIsAdminCacheContext'
1 service uses RouteIsAdminCacheContext
File
- src/
Cache/ Context/ RouteIsAdminCacheContext.php, line 14
Namespace
Drupal\menu_per_role\Cache\ContextView source
class RouteIsAdminCacheContext implements CacheContextInterface {
/**
* Context ID.
*
* @const string
*/
const CONTEXT_ID = 'route.is_admin';
/**
* The router admin context service.
*
* @var \Drupal\Core\Routing\AdminContext
*/
protected $adminContext;
/**
* RouteIsAdminCacheContext constructor.
*
* @param \Drupal\Core\Routing\AdminContext $adminContext
* The router admin context service.
*/
public function __construct(AdminContext $adminContext) {
$this->adminContext = $adminContext;
}
/**
* {@inheritdoc}
*/
public static function getLabel() {
return t('Route is admin');
}
/**
* {@inheritdoc}
*/
public function getContext() {
return $this->adminContext
->isAdminRoute() ? '1' : '0';
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
return new CacheableMetadata();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteIsAdminCacheContext:: |
protected | property | The router admin context service. | |
RouteIsAdminCacheContext:: |
constant | Context ID. | ||
RouteIsAdminCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
RouteIsAdminCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
RouteIsAdminCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |
|
RouteIsAdminCacheContext:: |
public | function | RouteIsAdminCacheContext constructor. |