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: joomla/Manual#716
No documentation changes for manual.joomla.org needed
| Status | New | ⇒ | Pending |
| Category | ⇒ | Front End com_content Libraries |
Hi,
Tested on 6.2-dev (6.2.1-dev nightly) with the PR's files applied. Menu-item URLs for categories, articles, contacts and news feeds are unchanged, as are "Remove IDs from URLs" on/off and the redirects for wrong aliases. But articles without a menu item of their own break: their links, /index.php/component/content/article/?catid=N, answer 404 (the base serves them).
Cause: in NomenuRules::parse() the new parseCallback branch only handles nestable views; the magic-method branch below it also has an else for non-nestable views (article), which the new branch lacks, so the article id is never parsed and the leftover segment gives a 404.
This pull request has been automatically rebased to 6.3-dev. Joomla! 6.2 is now in feature freeze.
| Title |
|
||||||
Hi,
Tested on 6.2-dev (6.2.1-dev nightly) with the PR's files applied. Menu-item URLs for categories, articles, contacts and news feeds are unchanged, as are "Remove IDs from URLs" on/off and the redirects for wrong aliases. But articles without a menu item of their own break: their links, /index.php/component/content/article/?catid=N, answer 404 (the base serves them).
Cause: in NomenuRules::parse() the new parseCallback branch only handles nestable views; the magic-method branch below it also has an else for non-nestable views (article), which the new branch lacks, so the article id is never parsed and the leftover segment gives a