Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[5.2] SEF/Router: Only merge default menu item when same component #43164

Merged
merged 16 commits into from
Jul 24, 2024

Conversation

Hackwar
Copy link
Member

@Hackwar Hackwar commented Mar 26, 2024

This fixes issues #43154, #35463 and #39149

Summary of Changes

The router right now merges the query elements of the current menu item into the query it parsed so far. If no menu item was found, it merges in the values of the default menu item. This is quite a problem when the default menu item contains query elements which are not overwritten by the URL itself. One example would be our own schedule runner plugin with a default menu item linking to an article. This PR only merges in the menu items query when the menu item and the parsed option are identical. Most likely this doesn't solve the issue entirely, since you could have a component which still could fail in this constellation, but at least it wouldn't fail anymore for all the components out there which currently have the query from an article default menu item merged into their request.

Testing Instructions

  1. Switch the default menu item to a single article view and select a random article.
  2. Edit plugins/system/schedulerunner/src/Extension/ScheduleRunner.php and add var_dump($id);die; to line 206
  3. Go to System -> Scheduled Tasks -> Options -> WebCron and enable Web Cron.
  4. Save the options and later copy the link from that same place to run the webcron via ajax call.
  5. Open the link in a new tab.

Actual result BEFORE applying this Pull Request

The var_dump() returns a non-zero ID, even though there is no ID in the URL.

Expected result AFTER applying this Pull Request

The var_dump() correctly only returns a 0.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@alikon
Copy link
Contributor

alikon commented Mar 27, 2024

should'nt this be backported to 4.4 ? as per #43154

@uGE70
Copy link

uGE70 commented Mar 27, 2024

I have tested this item ✅ successfully on 773a13f

Thanks a lot for your patch. I've tested it and the task id is returning zero now.


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

@Hackwar
Copy link
Member Author

Hackwar commented Mar 27, 2024

should'nt this be backported to 4.4 ? as per #43154

I'm unsure how this should be handled and asked the cms maintainer group about this. waiting for their feedback.

Co-authored-by: Harald Leithner <leithner@itronic.at>
@SniperSister
Copy link
Contributor

I have tested this item ✅ successfully on 8accc62


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

@Quy
Copy link
Contributor

Quy commented Apr 8, 2024

RTC


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Apr 8, 2024
@Hackwar Hackwar changed the title [5.2] Router: Only merge default menu item when same component [5.2] SEF/Router: Only merge default menu item when same component Apr 9, 2024
@brianteeman
Copy link
Contributor

Surely having to change an existing test that passes without this PR in order for it to pass with this PR is a red flag that something is wrong with this PR

@robbiejackson
Copy link

Good to get this bug fixed! It shouldn't merge in the parameters of the home menuitem.

However, the code is now not setting the active menuitem. This is a problem as extension developers do use this.

In Joomla 3.x the active menuitem wasn't set in the case of the home menuitem being used as default.

Then in Joomla 4 it changed to being set.

So in my opinion we shouldn't be now changing it back to the case where it's not set.

If the balance of opinion is that it shouldn't be set then this side-effect needs to be clearly highlighted in the documentation of the pull request.

See https://docs.joomla.org/Menu_and_Menuitems_API_Guide#Active_Menu_Item and
https://manual.joomla.org/docs/general-concepts/menus-menuitems#active-menu-item

@Hackwar
Copy link
Member Author

Hackwar commented Jul 19, 2024

Thank you @robbiejackson. Your comment made me check this again and do a debugging session of several hours and after several checks I indeed agree that we should still set the active menu item. I changed the code accordingly. Good catch. Our code actually states that getActive() might return null when no menu item is set, but who reads docblocks? ;-)

@Hackwar
Copy link
Member Author

Hackwar commented Jul 19, 2024

@uGE70, @SniperSister, @robbiejackson could you test this again so that we hopefully can merge this into 5.2? Thank you!

@brianteeman
Copy link
Contributor

Surely having to change an existing test that passes without this PR in order for it to pass with this PR is a red flag that something is wrong with this PR

image

whoever could have predicted that you dont edit a test to fix a problem

@uGE70
Copy link

uGE70 commented Jul 19, 2024

I have tested this item ✅ successfully on 359bbde


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

@robbiejackson
Copy link

I have tested this item ✅ successfully on 359bbde

Thanks for changing to keep the active menuitem :-)

I'll update the joomla manual documentation to confirm that the menuitem is now always set.


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

@Hackwar
Copy link
Member Author

Hackwar commented Jul 19, 2024

@robbiejackson this is actually something which I would keep vague for now. The getActive() method states that it can also return null and I'm currently still considering it to be more correct to not set the menu item in this case. However that would be a b/c break and thus has to wait until at least 6.0.

@Hackwar
Copy link
Member Author

Hackwar commented Jul 19, 2024

Thanks for the tests!

@zero-24
Copy link
Contributor

zero-24 commented Jul 21, 2024

I have tested this item ✅ successfully on bfa035f


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

1 similar comment
@SniperSister
Copy link
Contributor

I have tested this item ✅ successfully on bfa035f


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

@rdeutz rdeutz merged commit a03c8ad into joomla:5.2-dev Jul 24, 2024
3 checks passed
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jul 24, 2024
@Quy Quy added this to the Joomla! 5.2.0 milestone Jul 24, 2024
@Hackwar Hackwar deleted the 5.2-router-default branch July 26, 2024 17:26
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.