Переопределение существующего маршрута Друпал

commerce_custom_cart_redirect/commerce_custom_cart_redirect.info.yml

name: "Custom Cart Redirect"
type: module
core: 8.x
package: "utilvideo"

commerce_custom_cart_redirect/commerce_custom_cart_redirect.routing.yml

commerce_custom_cart_redirect.cart:
  path: '/cart_custom'
  defaults:
    _controller: '\Drupal\commerce_custom_cart_redirect\Controller\CustomCartController::index'
    _title: 'Shopping cart'
  requirements:
    _access: 'TRUE'

commerce_custom_cart_redirect/commerce_custom_cart_redirect.services.yml

services:
  commerce_custom_cart_redirect.route_subscriber:
    class: Drupal\commerce_custom_cart_redirect\Routing\RoutingSubscriber
    tags:
      - { name: event_subscriber }

commerce_custom_cart_redirect/src/Controller/CustomCartController.php

<?php

namespace Drupal\commerce_custom_cart_redirect\Controller;

use Drupal\Core\Controller\ControllerBase;

class CustomCartController extends ControllerBase {
  public function index(){
    return [
      '#type' => 'markup',
      '#markup' => 'custom cart'
    ];
  }
}

commerce_custom_cart_redirect/src/Routing/RoutingSubscriber.php

<?php

namespace Drupal\commerce_custom_cart_redirect\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;

class RoutingSubscriber extends RouteSubscriberBase {

  protected function alterRoutes(\Symfony\Component\Routing\RouteCollection $collection) {
    if($route = $collection->get('commerce_cart.page')){
      $route->setDefaults([
        "_controller" => "Drupal\commerce_custom_cart_redirect\Controller\CustomCartController::index",
        "_title" => "Shopping Cart"
      ]);
    }
  }
}

 

Моя сборка сайта и модулей Друпал 8 Часть 5
Моя сборка сайта и модулей Друпал 8 Часть 6
Советую почитать