Submitted by admin on
d7

We can achieve by using create a service. and for custom service we required to create custom modules

Step 1: Create the mymodule.info.yml

yml Copy
name: 'My Module'
description: 'Custom Module'
package: Custom
type: module
core: 8.x

Step 2: Create the mymodule.services.yml file in your custom module

yml Copy
services:
  mymodule.route_subscriber:
    class: Drupal\mymodule\RouteSubscriber
    arguments: []
    tags:
      - { name: event_subscriber }

Step:2 Create the src/RouteSubscriber.php Class :

php Copy

<?php
namespace Drupal\mymodule;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

/**
 * Class RouteSubscriber
 * @package Drupal\mymodule
 */
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * @param RouteCollection $collection
   */
  public function alterRoutes(RouteCollection $collection) {

if ($route = $collection->get('user.login')) { $route->setPath('/login'); }

}

d9