Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / block_access.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/hook/block_access.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/block_access.twig
new file mode 100644 (file)
index 0000000..970128e
--- /dev/null
@@ -0,0 +1,13 @@
+/**
+ * Implements hook_block_access().
+ */
+function {{ machine_name }}_block_access(\Drupal\block\Entity\Block $block, $operation, \Drupal\Core\Session\AccountInterface $account) {
+  // Example code that would prevent displaying the 'Powered by Drupal' block in
+  // a region different than the footer.
+  if ($operation == 'view' && $block->getPluginId() == 'system_powered_by_block') {
+    return AccessResult::forbiddenIf($block->getRegion() != 'footer')->addCacheableDependency($block);
+  }
+
+  // No opinion.
+  return AccessResult::neutral();
+}