-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Modern routing - remove view from query string #18429
Conversation
cee53c9
to
a908c46
Compare
@@ -182,14 +182,22 @@ public function parse(&$segments, &$vars) | |||
*/ | |||
public function build(&$query, &$segments) | |||
{ | |||
if (isset($query['Itemid'], $query['view']) === false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just if (!isset($query['view'], $query['Itemid'])) will make the code easier to read?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it will be easier to read.
// Get the menu item belonging to the Itemid that has been found | ||
$item = $this->router->menu->getItem($query['Itemid']); | ||
|
||
if (!isset($query['view'])) | ||
if ($item === null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also want to check and make sure the menu item is from the the component which we are process the routing? For example, change code to:
if ($item === null || $item->component != 'com_' . $this->router->getName())
So I looked at the code changes and also tested, it is working fine and solve the mentioned issue. However, there are some changes in the code which I am unsure if it is necessary, Maybe less change like I did here will still do the same thing https://github.com/joomla/joomla-cms/compare/staging...joomdonation:routing-fix-simpler?expand=1 |
A few changes is done because I want to present more explicit way for routing (layout). |
If I understand correctly, the additional changes you added to this PR is only needed if someone pass layout=default in JRoute::_ call (which is wrong, I think). The original code looks fine to me. We are working on a PR for staging, so I would stay on safe side, the less changes, the better, only the necessary change to address the issue should be implemented. |
@@ -198,7 +206,25 @@ public function build(&$query, &$segments) | |||
{ | |||
$view = $views[$query['view']]; | |||
|
|||
if (isset($item->query[$view->key], $query[$view->key]) && $item->query[$view->key] == (int) $query[$view->key]) | |||
if ($view->key === false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make code consistent with other places in routing code, I think this should be changed back to if (!$view->key)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted the code to be clearer. Ok I will change it back.
$item->query[$view->key] = 0; | ||
} | ||
|
||
if (isset($query[$view->key]) && $item->query[$view->key] == (int) $query[$view->key]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personal, I like the original code https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Component/Router/Rules/StandardRules.php#L201 instead of this change (requires added few lines of code above this line)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original code does not work for content edit form (Create Article).
Link to generate SEF is index.php?option=com_content&view=form&layout=edit&a_id=0
But in menu link is index.php?option=com_content&view=form&layout=edit
.
In this situation I assume the value of key (a_id) is 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I can see, link to create new article doesn't have a_id=0 in URL. Not sure where you get it? I tried to create a menu item to link to Create article menu option and the none sef link is index.php?option=com_content&view=form&layout=edit (not contains a_id=0) . So the original code should still work fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found it, for some reasons, a_id=0 is passed in some places in the code. Not sure why it is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @csthomas
When we create a menu item to link to Create Article menu option, Joomla somehow adds a_id=0 automatically to the URL of the menu item. You can see it by running this code (103 is the menu item I created to Create Article menu option)
$item = JFactory::getApplication()->getMenu()->getItem(103);
print_r($item->query);
It displays Array ( [option] => com_content [view] => form [layout] => edit [a_id] => 0 ) (note a_id = 0)
So as I can see, this change is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, it is set automatically at https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Component/Router/Rules/MenuRules.php#L231
I added it for some unit test that test StandardRule
class without loading MenuRule
class, some time ago. If we can trust that MenuRule
always is called before StandardRule
then OK. I will remove:
// If item has no key set, we assume 0.
if (!isset($item->query[$view->key]))
{
$item->query[$view->key] = 0;
}
I have tested this item ✅ successfully on 3d32326 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/18429. |
I reverted the code with non strict comparison to the false. |
@joomdonation can you please retest? |
@franz-wohlkoenig Will do after work. Maybe you can test it as well, just follow the instructions or ask us if needed. We need one more test anyway |
Cannot test next Days as i'm not at Home. |
I have tested this item ✅ successfully on 6396a6d This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/18429. |
I have tested this item ✅ successfully on 6396a6d This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/18429. |
Ready to Commit after two successful tests. |
Summary of Changes
Build a correct URL for links without layout or when the layout from URL is different than from menu item.
Testing Instructions
Install staging joomla or 3.8.2 with sample data.
On back-end enable modern routing in
users
.Optional enable
Allow User Registration
Go to home page and:
/index.php/password-reset?view=reset
/index.php/password-reset
/index.php/username-reminder?view=remind
/index.php/username-reminder
/index.php/login?view=login
/index.php/login
/index.php/registration-form?view=registration
/index.php/registration-form
/index.php/your-profile?view=profile&layout=edit
/index.php/your-profile?layout=edit
Expected result
Links with own menu item does not have a view parameter in query string.
Documentation Changes Required
No