joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

[5.3] SEF: Fix URLs when preprocessing

Open Hackwar opened this issue 1 year ago • 14 comments

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

  1. You need at least one article which is not directly linked to by a menu item.
  2. Edit an article and insert a link like index.php?option=com_content&view=article&id=<id> where id is the ID of the article which is NOT directly linked to by a menu item.
  3. 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

Hackwar avatar Aug 28 '24 11:08 Hackwar

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.

dautrich avatar Aug 28 '24 12:08 dautrich

My test wasn't successful. Here the screenshots:

Before applying the patch Before_linking_article Before_linked_article

After applying the patch After_linking_article After_linked_article

dautrich avatar Aug 28 '24 12:08 dautrich

As this PR is against 5.2, you have to also test this on 5.2-dev and not 5.1.

Hackwar avatar Aug 28 '24 12:08 Hackwar

When you link the category of the article in a menu item, you should have successfull tests.

Hackwar avatar Aug 28 '24 12:08 Hackwar

Since we are in feature freeze, I'm going to change the target of this PR to 5.3-dev.

Hackwar avatar Aug 28 '24 12:08 Hackwar

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?

dautrich avatar Aug 28 '24 14:08 dautrich

When you link the category of the article in a menu item, you should have successfull tests.

@Hackwar ???

dautrich avatar Aug 28 '24 14:08 dautrich

@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.

richard67 avatar Aug 28 '24 17:08 richard67

@dautrich beta1 should be enough.

@richard67 I'm aware. The tests are broken, since they are saving the contact with a broken catid.

Hackwar avatar Aug 28 '24 18:08 Hackwar

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.

dautrich avatar Aug 31 '24 11:08 dautrich

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

Elfangor93 avatar Sep 30 '24 11:09 Elfangor93

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.

Elfangor93 avatar Sep 30 '24 12:09 Elfangor93

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.

SniperSister avatar Oct 04 '24 08:10 SniperSister

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43992.

alikon avatar Oct 04 '24 08:10 alikon

Thanks to all who have worked on this PR.

rdeutz avatar Oct 29 '24 17:10 rdeutz