Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. UserRolesCacheContext.php

function UserRolesCacheContext::getContext

Overrides CalculatedCacheContextInterface::getContext

File

core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php, line 29

Class

UserRolesCacheContext
Defines the UserRolesCacheContext service, for "per role" caching.

Namespace

Drupal\Core\Cache\Context

Code

public function getContext($role = NULL) {
    if ($role === NULL) {
        return implode(',', $this->user
            ->getRoles());
    }
    else {
        return in_array($role, $this->user
            ->getRoles()) ? 'true' : 'false';
    }
}
RSS feed
Powered by Drupal