Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

RouteSubscriber disallow user routes

<?php

namespace DrupalcustomRouting;

use DrupalCoreRoutingRouteSubscriberBase;
use SymfonyComponentRoutingRouteCollection;

/**
 * Listens to the dynamic route events.
 */
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    // Always deny access to unwanted routes.
    $disallow_routes = [
      'user.login',
      'user.register',
      'user.pass',
    ];
    foreach ($disallow_routes as $disallow_route) {
      if ($route = $collection->get($disallow_route)) {
        $route->setRequirement('_access', 'FALSE');
      }
    }
  }

}
Source by drupal.stackexchange.com #
 
PREVIOUS NEXT
Tagged: #RouteSubscriber #disallow #user #routes
ADD COMMENT
Topic
Name
2+5 =