? Success

User tests: Successful: Unsuccessful:

avatar csthomas
csthomas
17 Dec 2018

Related to #23278

Summary of Changes

Joomla disallows us to create a SEF URL to menu item alias.
This PR changes that.

The main change is in

-				->select('e.element as component')
+				->select('COALESCE(e.element, ' . $db->quote('') . ') AS component')

which replace NULL with an empty string. That's all.
Other changes are made to optimize.

Testing Instructions

  1. Create a menu item alias on backend, ex: title= Alias URL, link index.php?Itemid=105
  2. Add in your active template file (index.php) such php code:
<?= \JRoute::('index.php?Itemid=105'); ?>

Note: to work correctly in a multilingual version, you must add the lang parameter.

<?= \JRoute::('index.php?Itemid=105&lang=en-GB'); ?>

Expected result

You will get a SEF URL /alias-url

Actual result

You get /?Itemid=105

Documentation Changes Required

No

avatar csthomas csthomas - open - 17 Dec 2018
avatar csthomas csthomas - change - 17 Dec 2018
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 17 Dec 2018
Category Libraries
avatar wilsonge
wilsonge - comment - 21 Dec 2018

Why do we want to have an SEF URL for an Alias. That's creating duplicate SEF content links, which is a bad thing as far as I understand.

avatar csthomas
csthomas - comment - 21 Dec 2018

If someone use menu item alias (#23278) without redirection then this PR also should be helpful to generate such links.

@sanderpotjer mentioned about AMP pages at #22432 (comment)

My idea is to let people choose one of two ways per each alias link.
For example, I have a menu item alias: /alias and its point to /canonical URL.

Options:

  1. Use redirection for alias link, always generate direct URL to target. The menu module always generate /canonical. If visitor somehow got to /alias then will be redirected to /canonical.

  2. Allow visitors to visit the /alias page (administrator can choose a different template). Allow creation of SEF URL to the alias page /alias. Probably, by 3rd party extension, it would be good to have a canonical <link ...> that will be directed to the /canonical URL.

To complete the second point I would like to propose an additional changes (to be B/C this probably requires additional parameter) in the menu module:

diff --git a/modules/mod_menu/helper.php b/modules/mod_menu/helper.php
index 96820f805d..b758184ec8 100644
--- a/modules/mod_menu/helper.php
+++ b/modules/mod_menu/helper.php
@@ -114,19 +114,42 @@ class ModMenuHelper
                                                        break;
 
                                                case 'alias':
-                                                       $item->flink = 'index.php?Itemid=' . $item->params->get('aliasoptions');
+                                                       $aliasRedirect = $item->params->get('alias_redirect');
+                                                       $newItemId     = $item->params->get('aliasoptions');
 
                                                        // Get the language of the target menu item when site is multilingual
                                                        if (JLanguageMultilang::isEnabled())
                                                        {
-                                                               $newItem = JFactory::getApplication()->getMenu()->getItem((int) $item-
>params->get('aliasoptions'));
+                                                               if ($aliasRedirect)
+                                                               {
+                                                                       $item->flink = 'index.php?Itemid=' . $newItemId;
+                                                                       $newItem     = $menu->getItem((int) $newItemId);
 
-                                                               // Use language code if not set to ALL
-                                                               if ($newItem != null && $newItem->language && $newItem->language !== '*')
+                                                                       // Use language code if not set to ALL
+                                                                       if ($newItem !== null && $newItem->language && $newItem->language !== '*')
+                                                                       {
+                                                                               $item->flink .= '&lang=' . $newItem->language;
+                                                                       }
+                                                               }
+                                                               else
                                                                {
-                                                                       $item->flink .= '&lang=' . $newItem->language;
+                                                                       $item->flink = 'index.php?Itemid=' . $item->id;
+
+                                                                       // Use language code if not set to ALL
+                                                                       if ($item->language && $item->language !== '*')
+                                                                       {
+                                                                               $item->flink .= '&lang=' . $item->language;
+                                                                       }
                                                                }
                                                        }
+                                                       elseif ($aliasRedirect)
+                                                       {
+                                                               $item->flink = 'index.php?Itemid=' . $newItemId;
+                                                       }
+                                                       else
+                                                       {
+                                                               $item->flink = 'index.php?Itemid=' . $item->id;
+                                                       }
                                                        break;
 
                                                default:

This way the /alias URL will be generated by the menu module only if you choose to no use redirection. (This is a new parameter in menu item alias.)
Otherwise the menu module will generate direct link to /canonical.

avatar laoneo
laoneo - comment - 4 Apr 2022

Sorry that it took so long to respond. As this is a new feature, can you rebase the branch on 4.2-dev, so we can get it properly reviewed and tested. In the meantime I'm closing it, when ready, please reopen again. Thanks for your help making Joomla better.

avatar laoneo laoneo - close - 4 Apr 2022
avatar laoneo laoneo - change - 4 Apr 2022
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2022-04-04 07:54:06
Closed_By laoneo
Labels Added: ?
Removed: ?

Add a Comment

Login with GitHub to post a comment