Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / service / access-checker.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/service/access-checker.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/service/access-checker.twig
new file mode 100644 (file)
index 0000000..c585ed3
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+namespace Drupal\{{ machine_name }}\Access;
+
+use Drupal\Core\Access\AccessResult;
+use Drupal\Core\Routing\Access\AccessInterface;
+use Symfony\Component\Routing\Route;
+
+/**
+ * Checks if passed parameter matches the route configuration.
+ *
+ * @DCG
+ * To make use of this access checker add '{{ applies_to }}: Some value' entry to route
+ * definition under requirements section.
+ */
+class {{ class }} implements AccessInterface {
+
+  /**
+   * Access callback.
+   *
+   * @param \Symfony\Component\Routing\Route $route
+   *   The route to check against.
+   * @param \ExampleInterface $parameter
+   *   The parameter to test.
+   *
+   * @return \Drupal\Core\Access\AccessResultInterface
+   *   The access result.
+   */
+  public function access(Route $route, \ExampleInterface $parameter) {
+    return AccessResult::allowedIf($parameter->getSomeValue() == $route->getRequirement('{{ applies_to }}'));
+  }
+
+}