d0818ef20689b5508b07e939baaddd237aca2fd3
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / node_access_records.twig
1 /**
2  * Implements hook_node_access_records().
3  */
4 function {{ machine_name }}_node_access_records(\Drupal\node\NodeInterface $node) {
5   // We only care about the node if it has been marked private. If not, it is
6   // treated just like any other node and we completely ignore it.
7   if ($node->private->value) {
8     $grants = [];
9     // Only published Catalan translations of private nodes should be viewable
10     // to all users. If we fail to check $node->isPublished(), all users would be able
11     // to view an unpublished node.
12     if ($node->isPublished()) {
13       $grants[] = [
14         'realm' => 'example',
15         'gid' => 1,
16         'grant_view' => 1,
17         'grant_update' => 0,
18         'grant_delete' => 0,
19         'langcode' => 'ca'
20       ];
21     }
22     // For the example_author array, the GID is equivalent to a UID, which
23     // means there are many groups of just 1 user.
24     // Note that an author can always view his or her nodes, even if they
25     // have status unpublished.
26     if ($node->getOwnerId()) {
27       $grants[] = [
28         'realm' => 'example_author',
29         'gid' => $node->getOwnerId(),
30         'grant_view' => 1,
31         'grant_update' => 1,
32         'grant_delete' => 1,
33         'langcode' => 'ca'
34       ];
35     }
36
37     return $grants;
38   }
39 }