Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / module / content-entity / src / ExampleAccessControlHandler.php.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/module/content-entity/src/ExampleAccessControlHandler.php.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/module/content-entity/src/ExampleAccessControlHandler.php.twig
new file mode 100644 (file)
index 0000000..6ac5e9d
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+
+namespace Drupal\{{ machine_name }};
+
+use Drupal\Core\Access\AccessResult;
+use Drupal\Core\Entity\EntityAccessControlHandler;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Session\AccountInterface;
+
+/**
+ * Defines the access control handler for the {{ entity_type_label|lower }} entity type.
+ */
+class {{ class_prefix }}AccessControlHandler extends EntityAccessControlHandler {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
+
+    switch ($operation) {
+      case 'view':
+        return AccessResult::allowedIfHasPermission($account, 'view {{ entity_type_label|lower }}');
+
+      case 'update':
+        return AccessResult::allowedIfHasPermissions($account, ['edit {{ entity_type_label|lower }}', 'administer {{ entity_type_label|lower }}'], 'OR');
+
+      case 'delete':
+        return AccessResult::allowedIfHasPermissions($account, ['delete {{ entity_type_label|lower }}', 'administer {{ entity_type_label|lower }}'], 'OR');
+
+      default:
+        // No opinion.
+        return AccessResult::neutral();
+    }
+
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
+    return AccessResult::allowedIfHasPermissions($account, ['create {{ entity_type_label|lower }}', 'administer {{ entity_type_label|lower }}'], 'OR');
+  }
+
+}