X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fhook%2Fnode_access_records.twig;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fhook%2Fnode_access_records.twig;h=d0818ef20689b5508b07e939baaddd237aca2fd3;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/hook/node_access_records.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/node_access_records.twig new file mode 100644 index 000000000..d0818ef20 --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/node_access_records.twig @@ -0,0 +1,39 @@ +/** + * Implements hook_node_access_records(). + */ +function {{ machine_name }}_node_access_records(\Drupal\node\NodeInterface $node) { + // We only care about the node if it has been marked private. If not, it is + // treated just like any other node and we completely ignore it. + if ($node->private->value) { + $grants = []; + // Only published Catalan translations of private nodes should be viewable + // to all users. If we fail to check $node->isPublished(), all users would be able + // to view an unpublished node. + if ($node->isPublished()) { + $grants[] = [ + 'realm' => 'example', + 'gid' => 1, + 'grant_view' => 1, + 'grant_update' => 0, + 'grant_delete' => 0, + 'langcode' => 'ca' + ]; + } + // For the example_author array, the GID is equivalent to a UID, which + // means there are many groups of just 1 user. + // Note that an author can always view his or her nodes, even if they + // have status unpublished. + if ($node->getOwnerId()) { + $grants[] = [ + 'realm' => 'example_author', + 'gid' => $node->getOwnerId(), + 'grant_view' => 1, + 'grant_update' => 1, + 'grant_delete' => 1, + 'langcode' => 'ca' + ]; + } + + return $grants; + } +}