RTC PR-4.4-dev Pending

User tests: Successful: Unsuccessful:

avatar Irata
Irata
2 Jan 2024

Adds separators as submenu's items for Components

Pull Request for Issue #41123 .

Summary of Changes

Alters the 'type' attribute for sub-menus when installing a Component to allow for separator lines to be added to the sub menu of a Component. For use when you need to break up or group sub-menu items of a Component.

In the manifest .xml file for a components you can indicate the placement of the separator by adding the element <menu type=separator>--<menu> between a set of elements.

---

The processing to read and render the separator already exists in the Joomla core, all that was missing was the ability to specify the 'type' of separator when installing a component. The rendering of the separator will either use the characters defined between the

and elements or the characters are stripped and the separator is rendered as a line with CSS.

Testing Instructions

Add the <menu type=separator>--<menu> element to the manifest .xml file of a component and Install the component in an instance of Joomla.

Below is a sample manifest .xml file that can be .zipped and installed to create a dummy component menu and sub-menu that will create the various separators.

<?xml version="1.0" encoding="utf-8" ?>
<extension type="component" method="upgrade">
    <name>com_testing</name>
    <creationDate>2024</creationDate>
    <author>someone</author>
    <authorEmail>somethingsomewhere.com</authorEmail>
    <authorUrl>something</authorUrl>
    <copyright>something</copyright>
    <license>GNU General Public License version 2 or later;</license>
    <version>1.0.0</version>
    <description>Testing</description>

    <!-- Back-end files -->
    <administration>
        <!-- Menu entries -->
        <menu view="emporium">Testing</menu>
        <submenu>
            <menu link="option=com_testing">Menu Item 1</menu>
            <menu type="separator">-----------------------</menu>
            <menu link="option=com_testing">Menu Item 2</menu>
            <menu type="separator" alias="second">.....................</menu>
            <menu link="option=com_testing">Menu Item 3</menu>
            <menu type="separator" alias="third">______________________</menu>
        </submenu>
        <files>
            <filename>testing.xml</filename>
        </files>
    </administration>
</extension>

Actual result BEFORE applying this Pull Request

Nothing happened. 'type=separator' is ignored and replaced with 'component'

Expected result AFTER applying this Pull Request

Expand your Component name under the Admin area Component Menu on the left and you should see the separator displayed as a sub menu item.

In the #__menu table the entry for your separator will have a field of type with the value 'separator' and the alias will be the current date

Link to documentations

Please select:

  • Documentation link for docs.joomla.org: https://docs.joomla.org/Manifest_files

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
3.00

avatar Irata Irata - open - 2 Jan 2024
avatar Irata Irata - change - 2 Jan 2024
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 2 Jan 2024
Category Libraries
avatar Irata Irata - change - 3 Jan 2024
Labels Added: PR-4.4-dev
avatar marcorensch
marcorensch - comment - 3 Jan 2024

It works as expected when adding one separator but when adding multiple via xml

<menu type="separator">--</menu>

it creates only one (the last one) in the database. The problem relies on the alias creation by using the "current-date" - the alias has to be unique. I've quickly tested my theory by changing the following:

$data['alias']        = (string) $child;

to:

$data['alias']        = ((string) $child->attributes()->alias) ?: (string) $child;

and setting a custom alias on my separators like so:

<menu type="separator" alias="one">--</menu>
<menu type="separator" alias="two">--</menu>
...

Now the database elements got created. So the alias generation does not take care of the "uniqueness" of created / added elements here and replace the before created when adding the next separator to the database.

What you can do in your XML to bring it to work is to give them unique content:

<menu type="separator">one</menu>
<menu type="separator">two</menu>
...

The Problem is that in unpatched state the items got then also rendered like a default menu item including its label. So installing a component that makes use of this feature will lead to rendered menu items "one" "two"...

So how about generating an unique alias here if the type is separator?
An option would be to count the separator types and increase a counter... someting clean and understandable like "component-separator-n":

...
$separatorCounter = 0;
foreach ($this->getManifest()->administration->submenu->menu as $child) {
...
if((string) $child->attributes()->type === 'separator') {
                $data['alias']        = $option . '-separator-' . $separatorCounter++;
            }
...

This would result in:
com-componentname-separator-0, com-componentname-separator-1, ...

avatar Irata Irata - change - 4 Jan 2024
The description was changed
avatar Irata Irata - edited - 4 Jan 2024
avatar Irata
Irata - comment - 4 Jan 2024

@marcorensch Thanks for testing and the feedback, I hadn't thought about testing it for multiple separators.

I like your first suggestion of updating just the alias assignment line,
$data['alias'] = ((string) $child->attributes()->alias) ?: (string) $child;
as the better solution and is simple to implement and document.

Using this example in the manifest .xml is shows the various combinations.

        <submenu>
            <menu link="option=com_testing">Menu Item 1</menu>
            <menu type="separator">-----------------------</menu>
            <menu link="option=com_testing">Menu Item 2</menu>
            <menu type="separator" alias="second">.....................</menu>
            <menu link="option=com_testing">Menu Item 3</menu>
            <menu type="separator" alias="third">______________________</menu>
        </submenu> 

Specifying an alias for the first separator is optional and only required for subsequent separators.

For Joomla instances that don't have this PR then only one separator will be saved in the table but the characters in the title can be used to create a character based separator.

This snippet of code in ..\administrator\modules\mod_menu\src\Menu\CssMenu.php (#461) is used to empty the title property and leave it to the css to draw the separator. For instance prior to this PR the condition is never met therefore the characters in the title are displayed.

            if ($item->type === 'separator' && $itemParams->get('text_separator') == 0) {
                $item->title = '';
            }
avatar marcorensch
marcorensch - comment - 4 Jan 2024

@Irata I would say that sounds like a good solution to cover all eventualities.

avatar Irata Irata - change - 7 Jan 2024
Title
Implement the ability to have 'separator' lines between sub menu item…
Implement 'separator' lines between sub menus in Admin Components
avatar Irata Irata - edited - 7 Jan 2024
avatar Irata Irata - change - 7 Jan 2024
Title
Implement 'separator' lines between sub menus in Admin Components
[4.4] Fix missing 'separator' lines between sub menus in Admin Components
avatar Irata Irata - edited - 7 Jan 2024
avatar Irata
Irata - comment - 7 Jan 2024

I have updated the the extra line to allow the alias to be specified when creating multiple separators.

Please review and test.

avatar MacJoom
MacJoom - comment - 10 Jan 2024

@Irata and @marcorensch thanks for the good work - @marcorensch could please mark a successful test in the issue tracker and remember: we still need another successful test

avatar Irata Irata - change - 10 Jan 2024
The description was changed
avatar Irata Irata - edited - 10 Jan 2024
avatar Irata
Irata - comment - 10 Jan 2024

I have updated the Testing instructions with a sample manifest .xml that can be used to test this PR.

avatar marcorensch marcorensch - test_item - 11 Jan 2024 - Tested successfully
avatar marcorensch
marcorensch - comment - 11 Jan 2024

I have tested this item ✅ successfully on e05f694


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

avatar fgsw fgsw - test_item - 12 Jan 2024 - Tested successfully
avatar fgsw
fgsw - comment - 12 Jan 2024

I have tested this item ✅ successfully on e05f694


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

avatar Quy Quy - change - 12 Jan 2024
Status Pending Ready to Commit
avatar Quy
Quy - comment - 12 Jan 2024

RTC


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

avatar Quy Quy - change - 12 Jan 2024
Labels Added: RTC
avatar MacJoom MacJoom - close - 14 Jan 2024
avatar MacJoom MacJoom - merge - 14 Jan 2024
avatar MacJoom MacJoom - change - 14 Jan 2024
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2024-01-14 22:44:30
Closed_By MacJoom

Add a Comment

Login with GitHub to post a comment