class NodeGrantsHelper

Same name and namespace in other branches
  1. main core/modules/node/src/NodeGrantsHelper.php \Drupal\node\NodeGrantsHelper

Defines some helpers for the node access control system relating to grants.

Hierarchy

Expanded class hierarchy of NodeGrantsHelper

3 files declare their use of NodeGrantsHelper
Access.php in core/modules/node/src/Plugin/views/filter/Access.php
node.module in core/modules/node/node.module
NodeAccessGrantsCacheContext.php in core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php
1 string reference to 'NodeGrantsHelper'
node.services.yml in core/modules/node/node.services.yml
core/modules/node/node.services.yml
1 service uses NodeGrantsHelper
Drupal\node\NodeGrantsHelper in core/modules/node/node.services.yml
Drupal\node\NodeGrantsHelper

File

core/modules/node/src/NodeGrantsHelper.php, line 15

Namespace

Drupal\node
View source
class NodeGrantsHelper {
  public function __construct(protected readonly ModuleHandlerInterface $moduleHandler) {
  }
  
  /**
   * Fetches an array of permission IDs granted to the given user ID.
   *
   * The implementation here provides only the universal "all" grant. A node
   * access module should implement hook_node_grants() to provide a grant list
   * for the user.
   *
   * After the default grants have been loaded, we allow modules to alter the
   * grants array by reference. This hook allows for complex business logic to
   * be applied when integrating multiple node access modules.
   *
   * @param string $operation
   *   The operation that the user is trying to perform.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The account object for the user performing the operation.
   *
   * @return array
   *   An associative array in which the keys are realms, and the values are
   *   arrays of grants for those realms.
   */
  public function nodeAccessGrants(string $operation, AccountInterface $account) : array {
    // Fetch node access grants from other modules.
    $grants = $this->moduleHandler
      ->invokeAll('node_grants', [
      $account,
      $operation,
    ]);
    // Allow modules to alter the assigned grants.
    $this->moduleHandler
      ->alter('node_grants', $grants, $account, $operation);
    return array_merge([
      'all' => [
        0,
      ],
    ], $grants);
  }

}

Members

Title Sort descending Modifiers Object type Summary
NodeGrantsHelper::nodeAccessGrants public function Fetches an array of permission IDs granted to the given user ID.
NodeGrantsHelper::__construct public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.