User tests: Successful: Unsuccessful:
The current advanced component router with the router rules depends on methods in the router with magic names like get<ViewName>Segment() and get<ViewName>Id(), which can not be parsed by static code analysers or IDEs. This makes it error prone and is also difficult for developers to understand. At the same time, this means that we are duplicating a lot of code to handle categories in all routers the same way and we need empty methods for constructs like category and categories.
This PR introduces a new configuration in the RouterViewConfiguration class where you can explicitely set these callbacks instead of relying on the magic methods. This means not only that you could use methods outside of the router to build or parse the segment, but also that third party code could override the behavior without changing the router itself. Also, this introduces the CategoryCallbackTrait, which takes the category behavior from the different core routers and puts them into a reusable trait. The whole change is also entirely backwards compatible, since it still falls back to the magic methods if no callback is registered.
To use the new method, simply extend the configuration of your view with ->setBuildCallback([$this, 'yourBuildCallbackMethod']) and ->setParseCallback([$this, 'yourParseCallbackMethod']). If you want to use the CategoryCallbackTrait, use it in your components router, set the category factory in the constructor, add ->setParseCallback([$this, 'getCategoryId'])->setBuildCallback([$this, 'getCategorySegment']); to your category and categories view and remove your custom methods in your router to use the ones from the trait instead.
noIDs attribute, which exists in the core content routers. Third party extensions might not support this at all and not have that attribute. Which way should we go here?See that your URLs still remain the same and work as before. Notice that the URLs and routing of com_contact and com_newsfeeds still work fine, even though they haven't been touched yet.
Please select:
Documentation link for guide.joomla.org:
No documentation changes for guide.joomla.org needed
Pull Request link for manual.joomla.org:
No documentation changes for manual.joomla.org needed
| Status | New | ⇒ | Pending |
| Category | ⇒ | Front End com_content Libraries |