Mercurial > hg > cmmr2012-drupal-site
annotate vendor/chi-teck/drupal-code-generator/templates/d8/service/access-checker.twig @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | c75dbcec494b |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\{{ machine_name }}\Access; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\Core\Access\AccessResult; |
Chris@0 | 6 use Drupal\Core\Routing\Access\AccessInterface; |
Chris@0 | 7 use Symfony\Component\Routing\Route; |
Chris@0 | 8 |
Chris@0 | 9 /** |
Chris@0 | 10 * Checks if passed parameter matches the route configuration. |
Chris@0 | 11 * |
Chris@0 | 12 * @DCG |
Chris@0 | 13 * To make use of this access checker add '{{ applies_to }}: Some value' entry to route |
Chris@0 | 14 * definition under requirements section. |
Chris@0 | 15 */ |
Chris@0 | 16 class {{ class }} implements AccessInterface { |
Chris@0 | 17 |
Chris@0 | 18 /** |
Chris@0 | 19 * Access callback. |
Chris@0 | 20 * |
Chris@0 | 21 * @param \Symfony\Component\Routing\Route $route |
Chris@0 | 22 * The route to check against. |
Chris@0 | 23 * @param \ExampleInterface $parameter |
Chris@0 | 24 * The parameter to test. |
Chris@0 | 25 * |
Chris@0 | 26 * @return \Drupal\Core\Access\AccessResultInterface |
Chris@0 | 27 * The access result. |
Chris@0 | 28 */ |
Chris@0 | 29 public function access(Route $route, \ExampleInterface $parameter) { |
Chris@0 | 30 return AccessResult::allowedIf($parameter->getSomeValue() == $route->getRequirement('{{ applies_to }}')); |
Chris@0 | 31 } |
Chris@0 | 32 |
Chris@0 | 33 } |