You are here

protected function RouteSubscriber::alterRoutes in Custom Permissions 8.2

Same name and namespace in other branches
  1. 8 src/Routing/RouteSubscriber.php \Drupal\config_perms\Routing\RouteSubscriber::alterRoutes()

Alters existing routes for a specific collection.

Parameters

\Symfony\Component\Routing\RouteCollection $collection: The route collection for adding routes.

Overrides RouteSubscriberBase::alterRoutes

File

src/Routing/RouteSubscriber.php, line 20

Class

RouteSubscriber
Class RouteSubscriber.

Namespace

Drupal\config_perms\Routing

Code

protected function alterRoutes(RouteCollection $collection) {
  $custom_perms = CustomPermsEntity::loadMultiple();

  /** @var \Drupal\config_perms\Entity\CustomPermsEntity $custom_perm */
  foreach ($custom_perms as $custom_perm) {
    if ($custom_perm
      ->getStatus()) {
      $routes = config_perms_parse_path($custom_perm
        ->getRoute());
      foreach ($routes as $route) {
        if ($route = $collection
          ->get($route)) {

          // This overrides the route requirements removing all the other
          // access checkers and leaving only our access checker.
          $route
            ->setRequirements([
            '_config_perms_access_check' => 'TRUE',
          ]);
        }
      }
    }
  }
}