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_alter.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/hook/node_access_records_alter.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/node_access_records_alter.twig
new file mode 100644 (file)
index 0000000..0004dc5
--- /dev/null
@@ -0,0 +1,15 @@
+/**
+ * Implements hook_node_access_records_alter().
+ */
+function {{ machine_name }}_node_access_records_alter(&$grants, Drupal\node\NodeInterface $node) {
+  // Our module allows editors to mark specific articles with the 'is_preview'
+  // field. If the node being saved has a TRUE value for that field, then only
+  // our grants are retained, and other grants are removed. Doing so ensures
+  // that our rules are enforced no matter what priority other grants are given.
+  if ($node->is_preview) {
+    // Our module grants are set in $grants['example'].
+    $temp = $grants['example'];
+    // Now remove all module grants but our own.
+    $grants = ['example' => $temp];
+  }
+}