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

Breadcrumb

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

function UserRole::getCacheContexts

Overrides ContextAwarePluginTrait::getCacheContexts

File

core/modules/user/src/Plugin/Condition/UserRole.php, line 95

Class

UserRole
Provides a 'User Role' condition.

Namespace

Drupal\user\Plugin\Condition

Code

public function getCacheContexts() {
    // Optimize cache context, if a user cache context is provided, only use
    // user.roles, since that's the only part this condition cares about.
    $contexts = [];
    foreach (parent::getCacheContexts() as $context) {
        $contexts[] = $context == 'user' ? 'user.roles' : $context;
    }
    return $contexts;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal