Change route without changing .yml? Change RouteCollection?

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

Change route without changing .yml? Change RouteCollection?

Post by cangor » Tue Jan 09, 2018 6:05 pm

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: 543
Joined: Sun Apr 13, 2014 1:47 am
Location: Grenoble - France

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

Post by nicofuma » Sun Jan 21, 2018 10:33 am

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
Extension Customisations
Extension Customisations
Posts: 2976
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

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

Post by kasimi » Mon Jan 22, 2018 7:04 pm

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”

Who is online

Users browsing this forum: No registered users and 9 guests