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

Breadcrumb

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

function NodeAccessGrantsCacheContext::checkNodeGrants

Checks the node grants for the given operation.

Parameters

string $operation: The operation to check the node grants for.

Return value

string The string representation of the cache context.

1 call to NodeAccessGrantsCacheContext::checkNodeGrants()
NodeAccessGrantsCacheContext::getContext in core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php
Returns the string representation of the cache context.

File

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

Class

NodeAccessGrantsCacheContext
Defines the node access view cache context service.

Namespace

Drupal\node\Cache

Code

protected function checkNodeGrants($operation) {
    // When checking the grants for the 'view' operation and the current user
    // has a global view grant (i.e. a view grant for node ID 0) — note that
    // this is automatically the case if no node access modules exist (no
    // hook_node_grants() implementations) then we don't need to determine the
    // exact node view grants for the current user.
    if ($operation === 'view' && node_access_view_all_nodes($this->user)) {
        return 'view.all';
    }
    $grants = node_access_grants($operation, $this->user);
    $grants_context_parts = [];
    foreach ($grants as $realm => $gids) {
        $grants_context_parts[] = $realm . ':' . implode(',', $gids);
    }
    return $operation . '.' . implode(';', $grants_context_parts);
}

API Navigation

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