When I look at the code used for the method handling a RoutingEvents::DYNAMIC event, which receives a RouteBuildEvent object, I notice the code is always similar to the following one.

$collection = $event->getRouteCollection();
$route = new Route("$path/display", array('_form' => '\Drupal\field_ui\DisplayOverview') + $defaults, array('_permission' => 'administer ' . $entity_type . ' display'));
$collection->add("field_ui.display_overview.$entity_type", $route);

Since the RouteCollection class defines the RouteCollection::remove() method, would not removing routes from the collection be possible? I was thinking of removing a route to redefine it.


There is also a RoutingEvents::ALTER event, which runs afterward.

You can think of the difference between RoutingEvents::DYNAMIC and RoutingEvents::ALTER as similar to the difference between hook_menu() and hook_menu_alter().

There is a Views issue that discusses replacing routes, as opposed to removing and adding them, perhaps follow their example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.