RouteIsAdminCacheContext.php in Menu Per Role 8
File
src/Cache/Context/RouteIsAdminCacheContext.php
View source
<?php
declare (strict_types=1);
namespace Drupal\menu_per_role\Cache\Context;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\Context\CacheContextInterface;
use Drupal\Core\Routing\AdminContext;
class RouteIsAdminCacheContext implements CacheContextInterface {
const CONTEXT_ID = 'route.is_admin';
protected $adminContext;
public function __construct(AdminContext $adminContext) {
$this->adminContext = $adminContext;
}
public static function getLabel() {
return t('Route is admin');
}
public function getContext() {
return $this->adminContext
->isAdminRoute() ? '1' : '0';
}
public function getCacheableMetadata() {
return new CacheableMetadata();
}
}