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

Modern routing - remove view from query string #18429

Merged
merged 5 commits into from
Dec 7, 2017

Conversation

csthomas
Copy link
Contributor

@csthomas csthomas commented Oct 27, 2017

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

  1. Install staging joomla or 3.8.2 with sample data.

  2. On back-end enable modern routing in users.

  3. Optional enable Allow User Registration

  4. Go to home page and:

    • check module login links,
    • try to login with wrong password and check URL address after that
    • check URL address on profile edit form
    Before After
    /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

@csthomas csthomas changed the title Modern routing - fix urls with layout Modern routing - fix URL with layout and remove PHP Notice from URL with invalid Itemid Oct 27, 2017
@@ -182,14 +182,22 @@ public function parse(&$segments, &$vars)
*/
public function build(&$query, &$segments)
{
if (isset($query['Itemid'], $query['view']) === false)
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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())

@joomdonation
Copy link
Contributor

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

@csthomas
Copy link
Contributor Author

A few changes is done because I want to present more explicit way for routing (layout).
If there is no layout parameter in menu query this means that the default layout is 'default'.
I want to stay as it is now. My goal is #17746.

@joomdonation
Copy link
Contributor

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)
Copy link
Contributor

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)

Copy link
Contributor Author

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])
Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@csthomas csthomas Dec 2, 2017

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;
			}

@joomdonation
Copy link
Contributor

I have tested this item ✅ successfully on 3d32326

Works as described, done a code review, too. I am not happy with some changes in the code, but It might be personal coding style only


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

@csthomas
Copy link
Contributor Author

I reverted the code with non strict comparison to the false.

@ghost
Copy link

ghost commented Nov 30, 2017

@joomdonation can you please retest?

@joomdonation
Copy link
Contributor

@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

@ghost
Copy link

ghost commented Nov 30, 2017

Cannot test next Days as i'm not at Home.

@joomdonation
Copy link
Contributor

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.

@csthomas csthomas changed the title Modern routing - fix URL with layout and remove PHP Notice from URL with invalid Itemid Modern routing - remove view from query string Dec 6, 2017
@laoneo
Copy link
Member

laoneo commented Dec 7, 2017

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.

@ghost
Copy link

ghost commented Dec 7, 2017

Ready to Commit after two successful tests.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Dec 7, 2017
@mbabker mbabker added this to the Joomla 3.8.3 milestone Dec 7, 2017
@mbabker mbabker merged commit 27e730b into joomla:staging Dec 7, 2017
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Dec 7, 2017
@csthomas csthomas deleted the routing_build_with_layout branch December 7, 2017 13:08
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.

None yet

5 participants