Skip to content

Commit

Permalink
Add setting for maximum of nested menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruslan-Aleev committed Jun 19, 2023
1 parent 8b533fb commit b1d44d7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 9 additions & 0 deletions _build/data/transport.core.system_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,15 @@
'area' => 'manager',
'editedon' => null,
), '', true, true);
$settings['topmenu_subitems_max']= $xpdo->newObject('modSystemSetting');
$settings['topmenu_subitems_max']->fromArray(array (
'key' => 'topmenu_subitems_max',
'value' => '10',
'xtype' => 'textfield',
'namespace' => 'core',
'area' => 'manager',
'editedon' => null,
), '', true, true);
$settings['tree_default_sort']= $xpdo->newObject('modSystemSetting');
$settings['tree_default_sort']->fromArray(array (
'key' => 'tree_default_sort',
Expand Down
19 changes: 16 additions & 3 deletions manager/controllers/default/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function __construct(modManagerController &$controller)
$this->controller =& $controller;
$this->modx =& $controller->modx;
$this->showDescriptions = (boolean) $this->modx->getOption('topmenu_show_descriptions', null, true);
$this->subItemsMax = abs((int) $this->modx->getOption('topmenu_subitems_max', null, 0, true));
}

/**
Expand Down Expand Up @@ -194,7 +195,7 @@ public function buildMenu($name, $placeholder)

if (!empty($menu['children'])) {
$menuTpl .= '<ul class="modx-subnav">'."\n";
$this->processSubMenus($menuTpl, $menu['children']);
$this->processSubMenus($menuTpl, $menu['children'], $this->subItemsMax);
$menuTpl .= '</ul>'."\n";
}
$menuTpl .= '</li>'."\n";
Expand Down Expand Up @@ -303,9 +304,14 @@ public function hasPermission($perms)
*
* @return void
*/
public function processSubMenus(&$output, array $menus = array())
public function processSubMenus(&$output, array $menus = array(), $maxItems = false)
{
//$output .= '<ul class="modx-subnav">'."\n";
$moreMenu = '';
if ($maxItems && count($menus) > $maxItems) {
$moreMenu = array_slice($menus, $maxItems);
$menus = array_slice($menus, 0, $maxItems);
}

foreach ($menus as $menu) {
if (!$this->hasPermission($menu['permissions'])) {
Expand Down Expand Up @@ -333,14 +339,21 @@ public function processSubMenus(&$output, array $menus = array())

if (!empty($menu['children'])) {
$smTpl .= '<ul class="modx-subsubnav">'."\n";
$this->processSubMenus($smTpl, $menu['children']);
$this->processSubMenus($smTpl, $menu['children'], $this->subItemsMax);
$smTpl .= '</ul>'."\n";
}
$smTpl .= '</li>';
$output .= $smTpl;
$this->childrenCt++;
}

if (!empty($moreMenu)) {
$output .= '<li class="sub"><a href="#">...</a>'."\n";
$output .= '<ul class="modx-subsubnav more">'."\n";
$this->processSubMenus($output, $moreMenu, $this->subItemsMax);
$output .= '</ul>'."\n";
}

//$output .= '</ul>'."\n";
}

Expand Down

0 comments on commit b1d44d7

Please sign in to comment.