User tests: Successful: Unsuccessful:
Adds separators as submenu's items for Components
Pull Request for Issue #41123 .
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.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>
Nothing happened. 'type=separator' is ignored and replaced with 'component'
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
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
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Labels |
Added:
PR-4.4-dev
|
@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 = '';
}
Title |
|
Title |
|
I have updated the the extra line to allow the alias to be specified when creating multiple separators.
Please review and test.
@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
I have updated the Testing instructions with a sample manifest .xml that can be used to test this PR.
I have tested this item ✅ successfully on e05f694
I have tested this item ✅ successfully on e05f694
Status | Pending | ⇒ | Ready to Commit |
RTC
Labels |
Added:
RTC
|
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 |
It works as expected when adding one separator but when adding multiple via xml
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:
to:
and setting a custom alias on my separators like so:
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:
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":
This would result in:
com-componentname-separator-0
,com-componentname-separator-1
, ...