class NodeAccessTestLanguageHooks

Hook implementations for node_access_test_language.

Hierarchy

Expanded class hierarchy of NodeAccessTestLanguageHooks

File

core/modules/node/tests/modules/node_access_test_language/src/Hook/NodeAccessTestLanguageHooks.php, line 13

Namespace

Drupal\node_access_test_language\Hook
View source
class NodeAccessTestLanguageHooks {
  
  /**
   * Implements hook_node_grants().
   *
   * This module defines a single grant realm. All users belong to this group.
   */
  public function nodeGrants($account, $operation) : array {
    $grants['node_access_language_test'] = [
      7888,
    ];
    return $grants;
  }
  
  /**
   * Implements hook_node_access_records().
   */
  public function nodeAccessRecords(NodeInterface $node) : array {
    $grants = [];
    // Create grants for each translation of the node.
    foreach ($node->getTranslationLanguages() as $langcode => $language) {
      // If the translation is not marked as private, grant access.
      $translation = $node->getTranslation($langcode);
      $grants[] = [
        'realm' => 'node_access_language_test',
        'gid' => 7888,
        'grant_view' => empty($translation->field_private->value) ? 1 : 0,
        'grant_update' => 0,
        'grant_delete' => 0,
        'langcode' => $langcode,
      ];
    }
    return $grants;
  }

}

Members

Title Sort descending Modifiers Object type Summary
NodeAccessTestLanguageHooks::nodeAccessRecords public function Implements hook_node_access_records().
NodeAccessTestLanguageHooks::nodeGrants public function Implements hook_node_grants().

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