1

I'm having a problem with building the rule for a particular URL. Here's what I have in my system plugin:

//...
function onAfterInitialise() {
    require_once '/path/to/myhelper.php';
    $router = $this->app->getRouter();
    $router->attachBuildRule(array('MyHelper', 'BuildRoute'));
    $router->attachParseRule(array('MyHelper', 'ParseRoute'));
}
//...

In the myhelper.php:

class MyHelper {
     //...
     public static function buildRoute(&$router, &$uri) {
         $uri->setPath('foobar');
         $uri->setQuery(array());
     }
     //...
}

In another file, when I try to JRoute any url, it adds the language code at the end instead of the beginning. For example:

echo JRoute::_('helloworld.php');
//this will print "/foobar/en/" instead of just "/en/foobar/" or possibly just "/foobar"

A few things:

  1. I have the Joomla system plugin System - Language Filter enabled.

  2. Setting Remove URL Language Code to either Yes or No does not change the outcome.

  3. Disabling the plugin will remove the language code, but I can't do that.

  4. The baffling part is, all other Joomla generated URLs (like the ones in the menu), have the language code in front. eg mydomain.com/en/mylink

  5. Also baffling is if I do not try to override the route, Joomla show the language code in the front for the same JRoute::_('helloworld.php'). It shows /en/helloworld.

Any direction on this is greatly appreciated. Thanks in advance!

1 Answer 1

0

Your plugin is ordered before System - Language Filter. Changing the plugin order should fix the issue. Otherwise you may need to pass stage argument to attachBuildRule() and/or attachParseRule(). It defines at which stage of the build/parse process the rules are applied.

$router = $this->app->getRouter();
$router->attachBuildRule(array('MyHelper', 'BuildRoute'), $router::PROCESS_AFTER);

https://api.joomla.org/cms-3/classes/Joomla.CMS.Router.Router.html#method_attachBuildRule

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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