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

Breadcrumb

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

function NodeAccessGrantsCacheContext::getCacheableMetadata

Overrides CalculatedCacheContextInterface::getCacheableMetadata

File

core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php, line 84

Class

NodeAccessGrantsCacheContext
Defines the node access view cache context service.

Namespace

Drupal\node\Cache

Code

public function getCacheableMetadata($operation = NULL) {
    $cacheable_metadata = new CacheableMetadata();
    if (!\Drupal::moduleHandler()->hasImplementations('node_grants')) {
        return $cacheable_metadata;
    }
    // The node grants may change if the user is updated. (The max-age is set to
    // zero below, but sites may override this cache context, and change it to a
    // non-zero value. In such cases, this cache tag is needed for correctness.)
    $cacheable_metadata->setCacheTags([
        'user:' . $this->user
            ->id(),
    ]);
    // If the site is using node grants, this cache context can not be
    // optimized.
    return $cacheable_metadata->setCacheMaxAge(0);
}

API Navigation

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