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

[5.2] Allowing menu items to have multiple 'rel' values #39269

Draft
wants to merge 7 commits into
base: 5.2-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion administrator/components/com_menus/forms/item_url.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
label="COM_MENUS_ITEM_FIELD_ANCHOR_REL_LABEL"
default=""
validate="options"
layout="joomla.form.field.list-fancy-select"
multiple="true"
>
<option value="">JNONE</option>
<option value="alternate"/>
<option value="author"/>
<option value="bookmark"/>
Expand Down
3 changes: 2 additions & 1 deletion administrator/components/com_menus/forms/itemadmin_url.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
label="COM_MENUS_ITEM_FIELD_ANCHOR_REL_LABEL"
default=""
validate="options"
layout="joomla.form.field.list-fancy-select"
multiple="true"
>
<option value="">JNONE</option>
<option value="alternate"/>
<option value="author"/>
<option value="bookmark"/>
Expand Down
5 changes: 4 additions & 1 deletion modules/mod_menu/src/Helper/MenuHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,16 @@ public static function getList(&$params)
$item->flink = Route::_($item->flink);
}

// rel can have multiple values, combine the array into a space-separated string
$rel = is_array($itemParams->get('menu-anchor_rel')) ? implode(' ', $itemParams->get('menu-anchor_rel')) : $itemParams->get('menu-anchor_rel', '');
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't remember in Joomla Framework we have some method to join an array but it would be nice if we have something like,

$rel = ArrayHelper::join($itemParams->get('menu-anchor_rel'), ' ');

Then this code would have been very simple to read. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue is that I'm also checking if it's an array or not, because prior values would be a string. I'm going to be looking if there's a better way to solve this though without breaking b/c.

Copy link
Contributor

Choose a reason for hiding this comment

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

I 100% agree with your code change in this PR. I was trying to suggest that we may do something better by adding a generic class/method to avoid this kind of duplication. Also if we sniff our codebase there might be many places where it can be improved. :)


// We prevent the double encoding because for some reason the $item is shared for menu modules and we get double encoding
// when the cause of that is found the argument should be removed
$item->title = htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8', false);
$item->menu_icon = htmlspecialchars($itemParams->get('menu_icon_css', ''), ENT_COMPAT, 'UTF-8', false);
$item->anchor_css = htmlspecialchars($itemParams->get('menu-anchor_css', ''), ENT_COMPAT, 'UTF-8', false);
$item->anchor_title = htmlspecialchars($itemParams->get('menu-anchor_title', ''), ENT_COMPAT, 'UTF-8', false);
$item->anchor_rel = htmlspecialchars($itemParams->get('menu-anchor_rel', ''), ENT_COMPAT, 'UTF-8', false);
$item->anchor_rel = htmlspecialchars($rel, ENT_COMPAT, 'UTF-8', false);
$item->menu_image = htmlspecialchars($itemParams->get('menu_image', ''), ENT_COMPAT, 'UTF-8', false);
$item->menu_image_css = htmlspecialchars($itemParams->get('menu_image_css', ''), ENT_COMPAT, 'UTF-8', false);
}
Expand Down