Quantcast
Channel: Active questions tagged users - Drupal Answers
Viewing all articles
Browse latest Browse all 453

Alter existing routes doesn't work

$
0
0

I'm working on a D8 project trying to add custom access rules to some pages.

I want to restrict access to specific users based on their id.

I checked this and seems easy but I can't make it work!

I want to change the access for the route

entity.webform_submission.canonical/admin/structure/webform/manage/{webform}/submission/{webform_submission}

But as I didn't manage to make it work I tried an easier example

contact.site_page
/contact

(Which also doesn't work)

So I created my routing file under my_module/src/Routing folder :

namespace Drupal\my_module\Routing;use Drupal\Core\Routing\RouteSubscriberBase;use Symfony\Component\Routing\RouteCollection;/** * Listens to the dynamic route events. */class RouteSubscriber extends RouteSubscriberBase {  /**   * {@inheritdoc}   */  protected function alterRoutes(RouteCollection $collection) {    if ($route_item = $collection->get('contact.site_page')) {      $requirements = $route_item->getRequirements();      unset($requirements['_permission']);      $route_item->setRequirement('_access', 'FALSE');    }  }}

After that I added the service file in my_module's root folder:

services:  my_module.route_subscriber:    class: Drupal\my_module\Routing\RouteSubscriber    tags:      - { name: event_subscriber }

But I don't get Access denied when I visit those pages.

Also, is there any way to test it by using dsm or var_dump?

Any idea/help/suggestion?


Viewing all articles
Browse latest Browse all 453

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>