Created
December 2, 2017 09:43
-
-
Save keopx/fc84a88d4946ce399af276ef33666dd2 to your computer and use it in GitHub Desktop.
Alter routes options and requirements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\my_module\Routing; | |
use Drupal\Core\Routing\RouteSubscriberBase; | |
use Symfony\Component\Routing\RouteCollection; | |
/** | |
* Listens to the dynamic route events. | |
*/ | |
class JwtRouteSubscriber extends RouteSubscriberBase { | |
/** | |
* Alters existing routes for a specific collection. | |
* | |
* @param \Symfony\Component\Routing\RouteCollection $collection | |
* The route collection for adding routes. | |
*/ | |
public function alterRoutes(RouteCollection $collection) { | |
$urls = [ | |
'view.xxx.rest_artworks', | |
'view.uuu.rest_export_actives', | |
]; | |
foreach ($urls as $url) { | |
// Load the route, set authentication and add it again. | |
$route = $collection->get($url); | |
$route->setOption('_auth', ['jwt_auth', 'basic_auth', 'cookie']); | |
$route->setRequirement('_access', 'TRUE'); | |
$collection->add($url, $route); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
my_module.route_subscriber: | |
class: Drupal\my_module\Routing\JwtRouteSubscriber | |
tags: | |
- { name: event_subscriber } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment