JoomGallery allows you to add your custom routers. Here you can learn how to do this.
The basic Principle
In general, JoomGallery lists in its configuration all PHP files/routers that are located in the directory site\com_joomgallery\src\Service and contain Router in their name. To add a custom router, you therefore need to add a PHP file that contains a router class.
- To create a modern router, the router class must extend
Joomla\CMS\Component\Router\RouterView. - For a legacy router, the router class must implement
Joomla\CMS\Component\Router\RouterInterface.
The property $displayName is the display name of the router as it appears in the dropdown list in the configuration.
Take also a look into the general documentation of modern Routers:
Modern RouterA Modern Router
Creating a modern router is quite straightforward and effective. This is the template for a new router:
class CustomRouter extends DefaultRouter {
public static string $displayName = 'Custom Router';
public static string $image_parentID = 'catid';
public function __construct($app, $menu, $categoryFactory, $db) {
parent::__construct($app, $menu, $categoryFactory, $db, true);
// ... here come your custom RouterView definitions
}
}
In the constructor of the router class, alternative RouterViews can then be defined. For example, it can be specified that the URL of the detail view is generated directly as a child of the gallery view.
/gallery/1-flugzeug.html
This example requires the following RouterViews definitions:
$gallery = new RouterViewConfiguration('gallery');
$this->registerView($gallery);
$image = new RouterViewConfiguration('image');
$image->setKey('id')->setParent($gallery);
$this->registerView($image);
$this->attachRule(new MenuRules($this));
$this->attachRule(new StandardRules($this));
Using this principle, completely custom URLs can be generated according to entirely custom logic.