User tests: Successful: Unsuccessful:
Related to #23278
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.
Alias URL
, link index.php?Itemid=105
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'); ?>
You will get a SEF URL /alias-url
You get /?Itemid=105
No
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
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:
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
.
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
.
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.
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-04-04 07:54:06 |
Closed_By | ⇒ | laoneo | |
Labels |
Added:
?
Removed: ? |
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.