0

I cannot find any documentation on router changes for Joomla 4. Can anyone advise? It appears that placing a router.php file in the base directory for the component still works - although not in exactly the same way as for Joomla 3.

But Joomla components (e.g. com_banners) do not have a router.php in the base directory, instead having Router.php in src/Service. However, simply placing a similar Router.php file in src/Service in my own component seems to have no effect - it seems not to be activated. Does something have to be done to identify the router to Joomla? If so what and where? Is this preferred? Will the traditional router.php cease working at some point?

Also, can the same structure be used with Joomla 3.10? That is, can a component be built the same way to follow the new router convention and work in both Joomla 3.10 and 4.x?

I'd be grateful for any pointers.

5
  • Where are you now with converting to J4? Do you have services/provider.php file? Does it provide an instance of Joomla\CMS\Extension\ComponentInterface?
    – Sharky
    Sep 10 at 13:29
  • No, I don't. Thanks for answering my related question about what determines whether a component is legacy. I am struggling to find a suitable strategy for modernising a complex component that doesn't fit easily into the rigid Joomla component mould. It may be better to try to bring it up to date as a legacy component before worrying about going further.
    – mbrampton
    Sep 11 at 16:27
  • That would likely be an unnecessary step. J4 is actually meant to make extensions less reliant on naming conventions. Instead most things are based on interfaces. For example, if you have an unusual MVC structure, you can keep it by writing a custom MVC factory (implement Joomla\CMS\MVC\Factory\MVCFactoryInterface).
    – Sharky
    Sep 12 at 9:01
  • That certainly sounds worth investigation. Is there any documentation describing how to do it?
    – mbrampton
    Sep 14 at 11:37
  • I'm not aware of any documentation. But inspecting the interface and its two implementations in core (Joomla\CMS\MVC\Factory\MVCFactory and Joomla\CMS\MVC\Factory\LegacyFactory) should provide valuable information.
    – Sharky
    Sep 14 at 19:47
0

com_banners and other core components in J4 use service-based structure. For this the component needs to include a services/provider.php file which returns a service provider. The provider must provide a component instance in form of Joomla\CMS\Extension\ComponentInterface implementation. The component can implement a number of other interfaces. These implementations decide what common features are supported by a given component. So, for instance, to support routing the component must implement Joomla\CMS\Component\Router\RouterServiceInterface.

Also, can the same structure be used with Joomla 3.10?

No, J4 style extension do not work in J3. If you want to support both J3 and J4, stick with J3 conventions.

2
  • Thanks very much, your clarifications are most helpful. I think I need to go via code that works for both 3.10 and 4.x. For a pure 4.x version, is the Joomla MenuRules and StandardRules functionality described anywhere?
    – mbrampton
    Sep 14 at 11:37
  • As far as I know, router rules haven't changed since J3. There is a usage example in component development tutorial docs.joomla.org/Part_1:_The_Site_code#The_Component_Router. Besides that and the API documentation I don't know of any other documentation.
    – Sharky
    Sep 14 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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