[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX]: Ability to add separators items to visually separate items within a menu or submenu

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6941b8a21d1eb_2a17fafc11a@gitlab-sidekiq-low-urgency-cpu-bound-v2-68b4849589-lqxqw.mail>

Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
aacf1be0 by Grace Nshokano at 2025-12-16T19:44:29+00:00
[FIX]: Ability to add separators items to visually separate items within a menu or submenu
---
* [FIX] displaying separotar menu horizantaly

See merge request tikiwiki/tiki!8894

- - - - -


9 changed files:

- lib/core/Services/Menu/Controller.php
- lib/menubuilder/menulib.php
- lib/smarty_tiki/FunctionHandler/Menu.php
- templates/bootstrap_menu.tpl
- templates/bootstrap_smartmenu.tpl
- templates/bootstrap_smartmenu_children.tpl
- templates/bootstrap_smartmenu_megamenu_children.tpl
- templates/tiki-admin_menu_options.tpl
- themes/base_files/scss/_tiki-menus.scss


Changes:

=====================================
lib/core/Services/Menu/Controller.php
=====================================
@@ -246,7 +246,9 @@ class Services_Menu_Controller
             }
 
             $name = $input->name->text();
-            if (! $name) {
+            $type = $input->type->text();
+
+            if (! $name && $type !== '-') {
                 throw new Services_Exception_MissingValue('name');
             }
 
@@ -264,7 +266,6 @@ class Services_Menu_Controller
             }
 
             $url = $input->url->text();
-            $type = $input->type->text();
             $section = $input->section->text();
             $perm = $input->perm->text();
             $groupname = $input->asArray('groupname');


=====================================
lib/menubuilder/menulib.php
=====================================
@@ -276,10 +276,6 @@ class MenuLib extends TikiLib
             return $option;
         }, $options);
 
-        $treeOut = array_filter($treeOut, function ($option) {
-            return $option['type'] !== '-';
-        });
-
         if (isset($count)) {
             $options = [
                 'data' => $treeOut,


=====================================
lib/smarty_tiki/FunctionHandler/Menu.php
=====================================
@@ -126,31 +126,36 @@ class Menu extends Base
                         $element["sefurl"] = str_replace("--groupname--", $catName, $element["sefurl"]);
                         $element["canonic"] = str_replace("--groupname--", $catName, $element["canonic"]);
                     }
-                    if ($element['type'] !== '-') {
-                        $level = $element['sectionLevel'];
-                        // Creates new branch at level 0
-                        if ($level === 0) {
-                            $structured[] = $element;
-                            continue;
-                        }
 
-                        // Always selects last branch at level 0
-                        $branch = &$structured[count($structured) - 1];
+                    // Separators are added at level 0 without hierarchy processing
+                    if ($element['type'] === '-') {
+                        $structured[] = $element;
+                        continue;
+                    }
 
-                        // Selects nested part of the branch at element level
-                        for ($i = 0; $i < $level - 1; $i++) {
-                            if ($branch['children']) {
-                                $branch = &$branch['children'][count($branch['children']) - 1];
-                            }
-                        }
+                    $level = $element['sectionLevel'];
+                    // Creates new branch at level 0
+                    if ($level === 0) {
+                        $structured[] = $element;
+                        continue;
+                    }
+
+                    // Always selects last branch at level 0
+                    $branch = &$structured[count($structured) - 1];
 
-                        // Pushes the element at the end of selected element children.
-                        if (! empty($branch['children'])) {
-                            $branch['children'][] = $element;
-                        } else {
-                            $branch['children'] = [$element];
+                    // Selects nested part of the branch at element level
+                    for ($i = 0; $i < $level - 1; $i++) {
+                        if ($branch['children']) {
+                            $branch = &$branch['children'][count($branch['children']) - 1];
                         }
                     }
+
+                    // Pushes the element at the end of selected element children.
+                    if (! empty($branch['children'])) {
+                        $branch['children'][] = $element;
+                    } else {
+                        $branch['children'] = [$element];
+                    }
                 }
             }
 


=====================================
templates/bootstrap_menu.tpl
=====================================
@@ -55,13 +55,19 @@
                     </li>
                 {/if}
             {else}
-                <li class="nav-item {$item.class|escape|default:null} {if !empty($item.selected)}active{/if}">
-                    <a class="nav-link" href="{$item.sefurl|escape}">
-                        {if $menu_info.use_items_icons eq "y" && $item.icon}
-                            {icon name=$item.icon}
-                        {/if}{tr}{$item.name}{/tr}
-                    </a>
-                </li>
+                {if $item.type eq '-'}
+                    <li class="nav-item">
+                        <hr class="menu-separator my-2">
+                    </li>
+                {else}
+                    <li class="nav-item {$item.class|escape|default:null} {if !empty($item.selected)}active{/if}">
+                        <a class="nav-link" href="{$item.sefurl|escape}">
+                            {if $menu_info.use_items_icons eq "y" && $item.icon}
+                                {icon name=$item.icon}
+                            {/if}{tr}{$item.name}{/tr}
+                        </a>
+                    </li>
+                {/if}
             {/if}
         {/foreach}
     </ul>


=====================================
templates/bootstrap_smartmenu.tpl
=====================================
@@ -1,4 +1,8 @@
-{if not empty($item.children)}
+{if $item.type eq '-'}
+    <li class="sm-nav-item nav-item">
+        <hr class="menu-separator my-2">
+    </li>
+{elseif not empty($item.children)}
     <li class="sm-nav-item nav-item{if $item.selected|default:null} active{/if} {$item.class|escape} {if $module_params.megamenu eq 'y' and $module_params.megamenu_static eq 'y' }static{/if}">
         <a href="{$item.sefurl|escape}" class="sm-nav-link nav-link sm-sub-toggler">
             {if $menu_info.use_items_icons eq "y" && $item.icon}


=====================================
templates/bootstrap_smartmenu_children.tpl
=====================================
@@ -1,4 +1,6 @@
-{if not empty($item.children)}
+{if $item.type eq '-'}
+    <li class="dropdown-divider"></li>
+{elseif not empty($item.children)}
     <li class="sm-sub-item {if $item.selected|default:null} active{/if} {$item.class|escape}">
         <a href="{$item.sefurl|escape}" class="sm-sub-link dropdown-item sm-sub-toggler" data-bs-toggle="dropdown">
             {if $menu_info.use_items_icons eq "y" && $item.icon}


=====================================
templates/bootstrap_smartmenu_megamenu_children.tpl
=====================================
@@ -1,4 +1,6 @@
-{if not empty($item.children)}
+{if $item.type eq '-'}
+    <li class="dropdown-divider"></li>
+{elseif not empty($item.children)}
     <li class="mega-menu--item mega-menu--item-level-{$item.sectionLevel}">
         <a href="{$item.sefurl|escape}" class="" data-bs-toggle="dropdown">
             {if $menu_info.use_items_icons eq "y" && $item.icon}


=====================================
templates/tiki-admin_menu_options.tpl
=====================================
@@ -100,7 +100,13 @@
                                 <div class="label-group">
                                     <div class="input-group input-group-sm">
                                         <span class="input-group-text">{icon name='sort'}</span>
-                                        <input type="text" class="field-label form-control" value="{$option.name|escape}" placeholder="{tr}Label{/tr}">
+                                        {if $option.type eq '-'}
+                                            <div class="form-control d-flex align-items-center" style="background-color: #f8f9fa; padding: 0.5rem;">
+                                                <hr class="menu-separator">
+                                            </div>
+                                        {else}
+                                            <input type="text" class="field-label form-control" value="{$option.name|escape}" placeholder="{tr}Label{/tr}">
+                                        {/if}
                                         <span class="tips input-group-text option-edit" title="|{tr}Check this if the option is an alternative to the previous one.{/tr}">
                                                 <input type="checkbox" class="samepos"{if $option.position eq $prevpos} checked="checked"{/if}>
                                             {$prevpos = $option.position}


=====================================
themes/base_files/scss/_tiki-menus.scss
=====================================
@@ -180,9 +180,14 @@
     z-index: 3000;
 }
 
-@media (max-width: 768px) {
-    .modules.top_modules > .box-menu {
-        order: 999;
-        width: 100%;
-    }
-}
\ No newline at end of file
+/* Menu separator styling */
+.menu-separator {
+  border: none;
+  border-top: 1px solid #343a40;
+  width: 100%;
+  margin: 0.5rem 0;
+}
+
+.form-control .menu-separator {
+  margin: 0;
+}



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/aacf1be084e0085ef3f707f23a83f73ec3ccbf3b

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/aacf1be084e0085ef3f707f23a83f73ec3ccbf3b
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.