Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / node_access_records.twig
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 (file)
index 0000000..d0818ef
--- /dev/null
@@ -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;
+  }
+}