5 * Test module with a language-aware node access implementation.
7 * The module adds a 'private' field to page nodes that allows each translation
8 * of the node to be marked as private (viewable only by administrators).
11 use Drupal\node\NodeInterface;
14 * Implements hook_node_grants().
16 * This module defines a single grant realm. All users belong to this group.
18 function node_access_test_language_node_grants($account, $op) {
19 $grants['node_access_language_test'] = [7888];
24 * Implements hook_node_access_records().
26 function node_access_test_language_node_access_records(NodeInterface $node) {
29 // Create grants for each translation of the node.
30 foreach ($node->getTranslationLanguages() as $langcode => $language) {
31 // If the translation is not marked as private, grant access.
32 $translation = $node->getTranslation($langcode);
34 'realm' => 'node_access_language_test',
36 'grant_view' => empty($translation->field_private->value) ? 1 : 0,
40 'langcode' => $langcode,