function node_access_test_language_node_access_records

Same name in other branches
  1. 9 core/modules/node/tests/modules/node_access_test_language/node_access_test_language.module \node_access_test_language_node_access_records()
  2. 10 core/modules/node/tests/modules/node_access_test_language/node_access_test_language.module \node_access_test_language_node_access_records()
  3. 11.x core/modules/node/tests/modules/node_access_test_language/node_access_test_language.module \node_access_test_language_node_access_records()

Implements hook_node_access_records().

File

core/modules/node/tests/modules/node_access_test_language/node_access_test_language.module, line 26

Code

function node_access_test_language_node_access_records(NodeInterface $node) {
    $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,
            'priority' => 0,
            'langcode' => $langcode,
        ];
    }
    return $grants;
}

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