function NodeAccessTestLanguageHooks::nodeAccessRecords

Implements hook_node_access_records().

Attributes

#[Hook('node_access_records')]

File

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

Class

NodeAccessTestLanguageHooks
Hook implementations for node_access_test_language.

Namespace

Drupal\node_access_test_language\Hook

Code

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;
}

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