joomla-cms
joomla-cms copied to clipboard
[5.3] SEF: Fix URLs when preprocessing
Summary of Changes
The routing in Joomla requires some information to be in the query to build proper URLs. One is the slug, the combination of the ID and alias of a content item (for example &id=42:the-answer-to-everything) and the other is the parent key, if the extension requires this. (for example &catid=21) When this information is missing, the router can't build the right URL.
This PR adds a new component router rule, which should help fixing such URLs. The rule is supposed to be flexible enough to be used by most third party components. The parameters for the rule are the view configuration to act upon, the table to read the info from, the tables key and the tables parent key. The parent key is optional and the rule can be added more than once for different views.
Testing Instructions
- You need at least one article which is not directly linked to by a menu item.
- Edit an article and insert a link like
index.php?option=com_content&view=article&id=<id>whereidis the ID of the article which is NOT directly linked to by a menu item. - Check out the link in the frontend by visiting the article.
Actual result BEFORE applying this Pull Request
You get a strange link, for example something like /menuitem?view=article&id=42
Expected result AFTER applying this Pull Request
You get the correct link, for example /menuitem/this-test-is-successfull
Link to documentations
Please select:
-
[ ] Documentation link for docs.joomla.org:
-
[X] No documentation changes for docs.joomla.org needed
-
[ ] Pull Request link for manual.joomla.org:
-
[X] No documentation changes for manual.joomla.org needed
I have tested this item :red_circle: unsuccessfully on da8002a865a6eebb53354b85e107fa81838db60e
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43992.
My test wasn't successful. Here the screenshots:
Before applying the patch
After applying the patch
As this PR is against 5.2, you have to also test this on 5.2-dev and not 5.1.
When you link the category of the article in a menu item, you should have successfull tests.
Since we are in feature freeze, I'm going to change the target of this PR to 5.3-dev.
As this PR is against 5.2, you have to also test this on 5.2-dev and not 5.1.
@Hackwar Can I use 5.2beta1 or do I need a nightly build?
When you link the category of the article in a menu item, you should have successfull tests.
@Hackwar ???
@Hackwar System tests are failing:
Running: site/components/com_contact/Category.cy.js (48 of 124)
Test in frontend that the contact category view
✓ can display a list of contacts in a menu item (1282ms)
✓ can display a list of contacts without a menu item (663ms)
1) "after each" hook for "can open the contact form in the default layout"
2 passing (5s)
1 failing
1) Test in frontend that the contact category view
"after each" hook for "can open the contact form in the default layout":
Error: Unwanted PHP Warning: " Undefined array key 1 in <b>/tests/www/cmysql/components/com_contact/src/Service/Router.php</b> on line <b>163</b>"
Because this error occurred during a `after each` hook we are skipping all of the remaining tests.
@dautrich beta1 should be enough.
@richard67 I'm aware. The tests are broken, since they are saving the contact with a broken catid.
I have tested this item :white_check_mark: successfully on c57d285f4c8b43429cbc94faf4c69b739c33ada2
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43992.
Tested on naked 5.2.0-beta1, local with Laragon.
When applying this PR using the patch tester component, the Link to the article as well as its URL changes from
SEF Plugin, Strict Routing: No index.php/menuitem?view=article&id=2 (before this PR) to index.php/menuitem?view=article&id=2:autos&catid=2 (after this PR)
SEF Plugin, Strict Routing: Yes index.php/component/content/article/autos (before this PR) to index.php/component/content/article/autos?catid=2 (after this PR)
Joomla v5.2.0-beta3 PHP v8.1.2
I have tested this item :white_check_mark: successfully on 894383eb73af662cad44c902034b987c85456c03
See results of my test in the above comment. In consultation with the author of the PR the resulting behavior is as expected. Even if the case with activated strict routing in the SEF Plugin produces a bad result.
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43992.
I have tested this item :white_check_mark: successfully on 894383eb73af662cad44c902034b987c85456c03
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43992.
RTC
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43992.
Thanks to all who have worked on this PR.