glFusion / glfusion

glFusion CMS - Advanced Content Management with Style
https://www.glfusion.org
GNU General Public License v2.0
3 stars 0 forks source link

Allow dropdown menus from ADMIN_createMenu() #374

Closed leegarner closed 2 years ago

leegarner commented 4 years ago

For plugins with a large number of menu items it would be nice to have dropdown menus instead of over-populating the menu bar or creating pages with menus. This first pass, just editing lib-admin.php and layout/cms/admin/lists/topmenu.thtml, seems to work ok but the styling might be a little better.

index 6a627c6fc..3752e6446 100644
--- a/private/system/lib-admin.php
+++ b/private/system/lib-admin.php
@@ -893,6 +893,20 @@ function ADMIN_createMenu($menu_arr, $text, $icon = '')
         } else {
             $admin_templates->unset_var('menu_item_active');
         }
+
+        if (isset($menu_arr[$i]['submenu']) && is_array($menu_arr[$i]['submenu'])) {
+            $admin_templates->set_var('haschildren', true);
+            $admin_templates->set_block('top_menu', 'menu_submenu', 'menu_sm');
+            foreach ($menu_arr[$i]['submenu'] as $submenu) {
+                $admin_templates->set_var(array(
+                    'sm_url'   => $submenu['url'],
+                    'sm_text'  => $submenu['text'],
+                ) );
+                $admin_templates->parse('menu_sm', 'menu_submenu', true);
+            }
+        } else {
+            $admin_templates->unset_var('haschildren');
+        }
         $admin_templates->parse('menuvar', 'menu_items',true);
         $admin_templates->parse('alt_menuvar', 'alt_menu_items',true);
index 883afd0a7..eeb8a5e1b 100644
--- a/public_html/layout/cms/admin/lists/topmenu.thtml
+++ b/public_html/layout/cms/admin/lists/topmenu.thtml
@@ -2,7 +2,21 @@
 <nav class="uk-navbar tm-admin-navbar uk-margin">
        <ul class="uk-navbar-nav uk-hidden-small">
 <!-- BEGIN menu_items -->
-               <li {!if menu_item_active} class="uk-active" {!endif}><a href="{menu_item_url}">{menu_item_text}</a></li>
+{!if haschildren}
+                <li class="{!if menu_item_active}uk-active{!endif}uk-parent" data-uk-dropdown=>
+                    <a href="{menu_item_url}">{menu_item_text} <i class="uk-icon uk-icon-caret-down"></i></a>
+                    <div class="uk-dropdown uk-dropdown-navbar">
+                        <ul class="uk-nav uk-nav-navbar">
+<!-- BEGIN menu_submenu -->
+                            <li><a href="{sm_url}">{sm_text}</a></li>
+<!-- END menu_submenu -->
+                        </ul>
+                    </div>
+{!else}
+               <li {!if menu_item_active} class="uk-active" {!endif}>
+                    <a href="{menu_item_url}">{menu_item_text}</a>
+{!endif}
+                </li>
 <!-- END menu_items -->
        </ul>
 {!if lang_instructions}