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

Breadcrumb

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

function NodeAccessGrantsCacheContext::getContext

Overrides CalculatedCacheContextInterface::getContext

File

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

Class

NodeAccessGrantsCacheContext
Defines the node access view cache context service.

Namespace

Drupal\node\Cache

Code

public function getContext($operation = NULL) {
    // If the current user either can bypass node access then we don't need to
    // determine the exact node grants for the current user.
    if ($this->user
        ->hasPermission('bypass node access')) {
        return 'all';
    }
    // When no specific operation is specified, check the grants for all three
    // possible operations.
    if ($operation === NULL) {
        $result = [];
        foreach ([
            'view',
            'update',
            'delete',
        ] as $op) {
            $result[] = $this->checkNodeGrants($op);
        }
        return implode('-', $result);
    }
    else {
        return $this->checkNodeGrants($operation);
    }
}
RSS feed
Powered by Drupal