view 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
line wrap: on
line source
<?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 }}'));
  }

}