Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

If the link is the same as active menu item then use it #18260

Merged
merged 6 commits into from
Oct 15, 2017

Conversation

csthomas
Copy link
Contributor

@csthomas csthomas commented Oct 6, 2017

Pull Request for Issue #17719 and #16774

Summary of Changes

If link Itemid is equal to active menu and link query is equal to active query then use it, do not try to find a better match.
Add unit tests to prove that.

Testing Instructions

Use tests from #17719 or #16774 or this below.

  1. Turn off Search Engine Friendly URLs in Global Configuration
  2. Create menu item (Style 1) to an article, save, then save as copy (Style 2), publish and save and close.
  3. Go to front-page and click on the first one (Style 1), check both URLs, it is OK.
  4. Go to second (Style 2), and check link at (Style 2), the Itemid in URL point to (Style 1) instead to itself (Style 2).

Expected result

Active second menu item (Style 2) should have URL to (Style 2)

Actual result

Active second menu item (Style 2) use first menu item URL (Style 1)

Documentation Changes Required

No

@csthomas
Copy link
Contributor Author

csthomas commented Oct 6, 2017

@arrowthemes @weeblr

This small patch should fix your issues and it has chance to be merged in J3.8.x than my previous one #17746 that won't be merged in J3.8

To test you have to replace only one file libraries/src/Component/Router/Rules/MenuRules.php.

@esedic
Copy link
Contributor

esedic commented Oct 7, 2017

I have tested this item ✅ successfully on 94fae0c


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

// If the same view has two different menu items and one of them is active then use the active one
return;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem to be enough, it will fail in cases of URLs that have id variable, because
$activeQuery['id'] is id
$query['id'] is id:alias

so the equality comparison will fail, but its should have succeed, right ?

@infograf768
Copy link
Member

Not sure this works.
Test with 3 menu items displaying same article:
screen shot 2017-10-08 at 09 07 00

When clicking a second time on the same menu item, the itemid changes, except for the last one.
This screencapture displays the url(s) obtained at the bottom of the window.
itemid

@infograf768
Copy link
Member

@csthomas
Note: I also tested #17746 with the same menu items and when clicking a second time on the same menu item, it changes from the menu item itemid to the Home page menu item itemid.

@ggppdk
Copy link
Contributor

ggppdk commented Oct 8, 2017

@infograf768
it must be because of:
#18260 (comment)

@csthomas
Copy link
Contributor Author

csthomas commented Oct 8, 2017

Thanks @ggppdk @infograf768

PR #17746 after the last commit is broken for this test.

I added a new commit. I tested an article with menu styles with success.
Please test again.

@infograf768
Copy link
Member

At first sight, it was working OK, i.e. I got unique itemids for each of the menu items, even when clicking again on the same menu... but when clicking on the category link in the Article Info Category link, I get
[08-Oct-2017 16:12:19 Europe/Berlin] PHP Warning: explode() expects parameter 2 to be string, array given in /Applications/MAMP/htdocs/testnew/trunkgitnew/libraries/src/Component/Router/Rules/MenuRules.php on line 83

@csthomas
Copy link
Contributor Author

csthomas commented Oct 8, 2017

The problem was filter_key that is an array in category view.
As filter_key is not a part of routing then I use now only option, view, key (usual it is id) and layout.

@infograf768
Copy link
Member

@csthomas
Your last changes solve the category display warning, but we still have an error.

Test:
Create a menu item of type Create an article
Create a menu item of type Login form with option set to redirect to the Create an article menu item.
Login via this login form. url is here http://localhost:8888/testnew/trunkgitnew/index.php?option=com_users&view=login&Itemid=135&lang=en

Login is done OK, but I get a notice:
[09-Oct-2017 10:46:22 Europe/Berlin] PHP Notice: Undefined index: a_id in /Applications/MAMP/htdocs/testnew/trunkgitnew/libraries/src/Component/Router/Rules/MenuRules.php on line 103

The Notice is the same in multilang whether the redirect is set to a Create an article tagged to the same language as the login form or to another language.

@infograf768
Copy link
Member

In fact clicking directly on the Create article menu item also sends the Notice.
URL is:
http://localhost:8888/testnew/trunkgitnew/index.php?option=com_content&view=form&layout=edit&a_id=0&Itemid=134&lang=en

@infograf768
Copy link
Member

TBH, I am a bit concerned about B/C here.
I have only tested stuff concerning com_content, but are'nt we going to find other issues in other extensions, including 3rd party?

@csthomas
Copy link
Contributor Author

csthomas commented Oct 9, 2017

There is still an issue with B/C now.

@infograf768
Copy link
Member

Last commit solved the Notice for Create Article menu item.

@csthomas
Copy link
Contributor Author

csthomas commented Oct 9, 2017

As I can not use $view->key because it is only in newer routing I back to simpler way and only compare strings, if in query has array then this PR change nothing.

@csthomas
Copy link
Contributor Author

csthomas commented Oct 9, 2017

Current version does not work for category view because category view has query parameter filter_tag that is not used in build lookup. I can add a workaround for that by adding code in loop

if (strpos($k, 'filter_') === 0) continue; that will ignore every filter parameters.

@infograf768
Copy link
Member

@csthomas

If someone care about category view then such improvement could be add later.

What is the exact issue you have with category view?

@infograf768
Copy link
Member

What I remarked (and I do not see how to solve that aspect except by a new parameter), is that

  1. a link to article 1 in an article will always display the article1 menu item with highest id
  2. same for a link to a category in the article info when one has 2 single category menu items.
    Example a category blog has itemid 117 and category list or blog is itemid 136, then 136 will display.

@csthomas
Copy link
Contributor Author

csthomas commented Oct 10, 2017

Joomla routing is not a simple path.

Version for monolingual (If you do not use language parameter):

  • if you want to route to article then you look up for the lowest menu item id that match criteria.
    Version for multilingual (If appended parameter lang=...):
  • if you want to route to article then you look up for the highest menu item id that match criteria.

This is very weird but probably there ware some B/C issue.

The code is at https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Component/Router/Rules/MenuRules.php#L206 - the trick one

[Deleted]
...

@csthomas
Copy link
Contributor Author

csthomas commented Oct 10, 2017

  1. same for a link to a category in the article info when one has 2 single category menu items.
    Example a category blog has itemid 117 and category list or blog is itemid 136, then 136 will display.

[Updated]

It would be good to add new column/field "Routing Priority" to each menu item. This way we can manage which menu item (category menu) should be used for routing

After that you can set higher priority for menu item 117.
Then only first category menu will be used for articles routing.

@csthomas
Copy link
Contributor Author

Going back to this PR,

If someone care about category view then such improvement could be add later.

What is the exact issue you have with category view?

I'm surprised that it works for category menus.
Ok, then It is completed. Please test.

@infograf768
Copy link
Member

I have tested this item ✅ successfully on 8740d71

No more Notices or warnings.
Modules assignment work fine.


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

@ghost
Copy link

ghost commented Oct 12, 2017

@esedic can you please retest?

@esedic
Copy link
Contributor

esedic commented Oct 12, 2017

I have tested this item ✅ successfully on 8740d71

@franz-wohlkoenig, done



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

@ghost
Copy link

ghost commented Oct 12, 2017

RTC after two successful tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants