Score:0

Alter route path within event_subscriber with GET parameters

cn flag

I know I can alter route path with event_subscriber

class AdminRouteModifier extends RouteSubscriberBase {

  protected function alterRoutes(RouteCollection $collection) {
    if ($route = $collection->get('entity.admin.collection')) {
      // Set new path for the route
      $route->setPath('/admin/entity_admin_collection/newpath');
    }
  }

}

But I cannot find how to get link with GET parameters:
/admin/entity_admin_collection/newpath?sort=asc&order=Name

Is it possible within the event_subscriber?

4uk4 avatar
cn flag
Please clarify what you want to do. If this is for incoming requests you don't need to define GET parameters. If this is for outgoing links see for example https://www.drupal.org/docs/drupal-apis/menu-api/providing-module-defined-menu-links
Dimetry avatar
cn flag
I need to set outgoing links. And I've set it in aforementioned code (without GET parameters). But I don't know how to write correct code `$route->setPath('/admin/entity_admin_collection/newpath?sort=asc&order=Name')`. I found no solution from the link.
4uk4 avatar
cn flag
As said the incoming routes are defined without query string. In the mentioned documentation pages you find how to add new menu links with query args and hook_menu_links_discovered_alter() for existing menu links. The following chapters are for local tasks and action links.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.