Change route without changing .yml? Change RouteCollection?

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
cangor
Registered User
Posts: 86
Joined: Thu Oct 28, 2010 1:56 pm

Change route without changing .yml? Change RouteCollection?

Post by cangor »

Hello,

is there a way to change a route without changing the routing.yml?

For example forum-feeds:

Code: Select all

$url = $controller_helper->route('phpbb_feed_forum', array('forum_id' => $forum_id));
is defined in config/default/routing/feed.yml as:

Code: Select all

phpbb_feed_forum:
    path: /forum/{forum_id}
    defaults: { _controller: phpbb.feed.controller:forum }
    requirements:
        forum_id: \d+
Is there a way to change this in my extention for example to

Code: Select all

path: /forum/feeds/{forum_id}
without changing the file config/default/routing/feed.yml (which will be overwritten with the next update)? Perhaps via an event or by changing the RouteCollection (but where and how is the best way to do it)?
nicofuma
3.2 Release Manager
3.2 Release Manager
Posts: 546
Joined: Sun Apr 13, 2014 1:47 am
Location: Grenoble - France

Re: Change route without changing .yml? Change RouteCollection?

Post by nicofuma »

you can redefine the route by using the same name in your route: extensions are loaded after the core. But it may be difficult to pass validation
Paul wrote:
Member of phpBB Development-Team
No Support via PM
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Change route without changing .yml? Change RouteCollection?

Post by kasimi »

Subscribe to the core.common event, inject the router service and do this:

Code: Select all

$this->router->get_routes()->get('phpbb_feed_forum')->setPath('/forum/feeds/{forum_id}');
Post Reply

Return to “Extension Writers Discussion”