Skip to content

[com_menus] improve alias check and generation#10756

Merged
wilsonge merged 5 commits intojoomla:stagingfrom
andrepereiradasilva:menu-alias
Jun 15, 2016
Merged

[com_menus] improve alias check and generation#10756
wilsonge merged 5 commits intojoomla:stagingfrom
andrepereiradasilva:menu-alias

Conversation

@andrepereiradasilva
Copy link
Copy Markdown
Contributor

@andrepereiradasilva andrepereiradasilva commented Jun 8, 2016

Summary of Changes

This PR makes several changes on the menu alias generate process.

  • Improves alias generation
  • Improves alias conflict detection

Also solves some issues in the current alias generate process:

  1. In a monolingual site (language filter plugin disabled), create a menu item with the same alias as other menu item you have in the same/other menu root but with different language.

    You'll notice it will save with success but it shouldn't.

  2. In a multilingual site (language filter plugin enabled), create a menu item with the same alias as other menu item with All language you have in the same/other menu root but in a different language.

    You'll notice it will save with success but it shouldn't.

  3. Create a menu item of System Links -> Any type

    You'll notice the generate alias is the current date, not menu item title.

Testing Instructions

This needs to be tested with the proper attention.

  • Use latest staging and apply patch
  • Install one adicional language (example: fr-FR)
  • Create the following menu structure:
 Menu Type 1:
 - Menu item A: Language All, Alias: menu-item-a
 - Menu item B: Language en-GB, Alias: menu-item-b
 - Menu item C: Language fr-FR, Alias: menu-item-c
 Menu Type 2:
 - Menu item D: Language All, Alias: menu-item-d
 - Menu item E: Language en-GB, Alias: menu-item-e
 - Menu item F: Language fr-FR, Alias: menu-item-f
  • Apply patch
  • Set the site to monolingual (Disable Language Filter System plugin)
  • Change the alias in Menu item B to menu-item-a. It should give a error message.
  • Change the alias in Menu item F to menu-item-a. It should give a error message.
  • Now set the site to multilingual (Enable Language Filter System plugin)
  • Change the alias in Menu item B to menu-item-a. It should give a error message.
  • Change the alias in Menu item F to menu-item-e. It should save fine.
  • Change the alias in Menu item E to menu-item-a. It should give a error message.
  • Now create a menu item of System Type -> Menu alias and let it auto generate the alias. It should generate fine (without the date as alias).
  • Play a little with the alias and check everything is fine (test with and without unicode in global config).

Finally do a code review of the changes.

Observations

The alias cannot be duplicated in the following cases:

Monolingual Site (language filter plugin disabled)
  1. The menu item is at root level and has the same alias of other menu item that is at root level of any other menu.
  2. The menu item is not at root level, but was the has the same alias of other menu item that has the same parent.
Multilingual Site (language filter plugin enabled)
  1. The menu item language is "All", is at root level and has the same alias of other menu item (any language) that is at root level of any other menu.
  2. The menu item language is NOT "All", is at root level and has the same alias of other menu item (same or "All" language) that is at root level of any other menu.
  3. The menu item language is "All", is not at root level, but was the has the same alias of other menu item (any language) that has the same parent.
  4. The menu item language is "All", is not at root level, but was the has the same alias of other menu item (same or "All" language) that has the same parent.

@infograf768 please check if all is working fine.

@infograf768
Copy link
Copy Markdown
Member

Pleas set the $this->type= 'url' to empty to get a date as the alias is no use for an url and it will avoid an error if the alias is used for another menu item with same parent. THis was the reason it was implemented such originally.

@andrepereiradasilva
Copy link
Copy Markdown
Contributor Author

@infograf768 maybe adding a date to a menu item alias of the external link to "save alias" is not the correct behaviour.

Imagine the following scenario.

i have a parent menu item with a external link menu item type. And a child with a article menu item type.

In the before this patch scenario we get a SEF URL something like
/2016-06-08-11-40-42/test-menu-item-article
After this patch we get a /test-menu-item-external-link/test-menu-item-article

@infograf768
Copy link
Copy Markdown
Member

I have tested this item 🔴 unsuccessfully on d884169


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

@infograf768
Copy link
Copy Markdown
Member

Forget the unsuccesful test

@infograf768
Copy link
Copy Markdown
Member

I have tested this item ✅ successfully on d884169


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

@infograf768
Copy link
Copy Markdown
Member

Note: I understand you have prepared the PR to use different strings in the future, but is it really necessary at this point? For the moment, we just want to correct the bug (with ALL).

@infograf768
Copy link
Copy Markdown
Member

@brianteeman

You have already tested this. The only difference is that this PR does not change the error message as there was a debate on the link with target blank.
Can you please confirm thsi is working as it solves a long standing possible bug letting save a menu item alias with same alias as another with same parent when language ALL is concerned?

@brianteeman
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on d884169


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

@brianteeman
Copy link
Copy Markdown
Contributor

RTC


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jun 10, 2016
// The alias already exists. Send an error message.
if ($errorType)
{
$message .= JText::_('JLIB_DATABASE_ERROR_MENU_UNIQUE_ALIAS' . ($this->menutype != $table->menutype ? '_ROOT' : ''));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Concatenation with undefined variable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

undefined variable?

?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

$message was never defined before this line and this line uses .= operator.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you're right! thanks will correct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

corrected

@joomla-cms-bot
Copy link
Copy Markdown

This PR has received new commits.

CC: @brianteeman, @infograf768


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

@izharaazmi
Copy link
Copy Markdown
Contributor

Why we are having checks inside store method instead of check itself? Isn't it the whole purpose of check method to be!

Was there any specific reason?

@andrepereiradasilva
Copy link
Copy Markdown
Contributor Author

Just removed the dot from the message (shouldn't be a concatenation).
No issues, can still be RTC.

@andrepereiradasilva
Copy link
Copy Markdown
Contributor Author

Why we are having checks inside store method instead of check itself? Isn't it the whole purpose of check method to be!
Was there any specific reason?

I had that doubt also, didn't know why was like that, so reused what existed.
See https://github.com/joomla/joomla-cms/blob/staging/libraries/legacy/table/menu.php#L187

@izharaazmi
Copy link
Copy Markdown
Contributor

izharaazmi commented Jun 14, 2016

IMO, the data should be not strongly coupled with configuration as much as possible. If we can allow same alias for different language selection, that should be true even when multilingual is off (of course by still checking the language attribute). Because we won't be able to revalidate if the settings change.

And I don't think this matter is so straight forward. There must be some association check involved so as to allow alias sharing only for those items which just differ in language and not the content.

E.g. - Following can be a justifiable set to share same alias:

en = How to install Joomla?
es = Cómo instalar Joomla? 

But not for the following set:

en = How to change user permissions?
es = Cómo instalar Joomla?

I don't know what we should do about this, so thought to share here.

PS: es isn't my native language 😄

@andrepereiradasilva
Copy link
Copy Markdown
Contributor Author

IMO, the data should be not strongly coupled with configuration as much as possible.

I totally agree, but IMHO this is a very special case, is not everyday we change a site from multi-lingual to mono-lingual and vice-versa.

If we can allow same alias for different language selection, that should be true even when multilingual is off (of course by still checking the language attribute).

If we allow the same alias for two menu items in the root level in a mono-lingual site (not matter the language) we'll get the same url in the frontend for two menu items which cannot happen.

@infograf768 please check this.

@izharaazmi
Copy link
Copy Markdown
Contributor

izharaazmi commented Jun 14, 2016

... we'll get the same url in the frontend for two menu items ...

I undestand. Thats why I said

... I don't think this matter is so straight forward. There must be some association check involved ...

Edit:
But in that case we can choose to display the menu item which either matches '*' language or the site default language, ignoring other specific languages if monolingual is active and multiple items match for the queried alias. Yeah, too much complicated!

@infograf768
Copy link
Copy Markdown
Member

If we allow the same alias for two menu items in the root level in a mono-lingual site (not matter the language) we'll get the same url in the frontend for two menu items which cannot happen.
@infograf768 please check this.

indeed. pr is fine by solving this possible issue and i can't believe nobody saw that issue before...

@wilsonge wilsonge merged commit de1803a into joomla:staging Jun 15, 2016
@wilsonge wilsonge added this to the Joomla 3.6.0 milestone Jun 15, 2016
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jun 15, 2016
@andrepereiradasilva andrepereiradasilva deleted the menu-alias branch June 15, 2016 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants