modxbot / migrate

A testground for migrating issues and other such fun
0 stars 0 forks source link

Add a curent class for top menu in the Manager layout #10788

Open lossendae opened 14 years ago

lossendae commented 14 years ago

lossendae created Redmine issue ID 10788

Would it be possible to add current classes to the top menu (for the general section menu and childrens). It will allow to know in which section we are wihtout guessing and facilitate custom manager interface using tabs for top menu layout like evo.

splittingred commented 14 years ago

splittingred submitted:

Not without some serious reworking to the query. I'll look into it post-xpdo db work.

lossendae commented 13 years ago

lossendae submitted:

I made some changes to header.php controller to add current class to main and submenus by using the following code:

cacheManager->get('mgr/menus/'.$modx->getOption('manager_language',null,$modx->getOption('cultureKey',null,'en')));
if ($menus == null) {
    $menu = $modx->newObject('modMenu');
    $menus = $menu->rebuildCache();
    unset($menu);
}
$output = '';
$order = 0;
$current = $_GET['a'];
$showDescriptions = (boolean)$modx->getOption('topmenu_show_descriptions',null,true);
foreach ($menus as $menu) {
    $childrenCt = 0;
    $class= '';
    $childTpl= '';
    if (!empty($menu['permissions'])) {
        $permissions = array();
        $exploded = explode(',', $menu['permissions']);
        foreach ($exploded as $permission) $permissions[trim($permission)]= true;
        if (!empty($permissions) && !$modx->hasPermission($permissions)) continue;
    }

    if (!empty($menu['children'])) {
        $childTpl .= '
    '."\n"; _modProcessMenus($modx,$childTpl,$menu['children'],$childrenCt,$showDescriptions,$current,$class); $childTpl .= '
'."\n"; } $menuTpl = '
  • '."\n"; if (!empty($menu['handler'])) { $menuTpl .= ''.$menu['text'].''."\n"; } else if (!empty($menu['action'])) { $menuTpl .= ''.$menu['text'].''."\n"; } else { $menuTpl .= ''.$menu['text'].''."\n"; } $menuTpl .= $childTpl; $menuTpl .= '
  • '."\n"; /* if has no permissable children, and is not clickable, hide top menu item */ if (!empty($childrenCt) || !empty($menu['action']) || !empty($menu['handler'])) { $output .= $menuTpl; } $order++; } function _modProcessMenus(modX &$modx,&$output,$menus,&$childrenCt,$showDescriptions = true, $current,&$rowClass = '') { foreach ($menus as $menu) { if (!empty($menu['permissions'])) { $permissions = array(); $exploded = explode(',', $menu['permissions']); foreach ($exploded as $permission) $permissions[trim($permission)]= true; if (!empty($permissions) && !$modx->hasPermission($permissions)) continue; } $smTpl = '
  • '."\n"; if (isset($current) && is_numeric($current) && $current == $menu['action']) { $smTpl = '
  • '."\n"; $rowClass = ' current'; } $description = !empty($menu['description']) ? ''.$menu['description'].''."\n" : ''; if (!empty($menu['handler'])) { $smTpl .= ''.$menu['text'].($showDescriptions ? $description : '').''."\n"; } else { $url = '?a='.$menu['action'].$menu['params']; $smTpl .= ''.$menu['text'].($showDescriptions ? $description : '').''."\n"; } if (!empty($menu['children'])) { $smTpl .= '
      '."\n"; _modProcessMenus($modx,$smTpl,$menu['children'],$childrenCt,$showDescriptions); $smTpl .= '
    '."\n"; } $smTpl .= '
  • '; $output .= $smTpl; $childrenCt++; } } $firstClass= 'top first'; if(!$current){ $firstClass .= ' current'; } $modx->smarty->assign('first_class',$firstClass); $modx->smarty->assign('navb',$output); /* assign logged in text and link */ $profile = $modx->getObject('modMenu','profile'); $modx->smarty->assign('username',$modx->getLoginUserName()); $modx->smarty->assign('profileAction',$profile->get('action')); /* assign welcome back text */ $welcome_back = $modx->lexicon('welcome_back',array('name' => $modx->getLoginUserName())); $modx->smarty->assign('welcome_back',$welcome_back); unset($welcome_back); return $modx->smarty->fetch('header.tpl');

    And to navbar.tpl to allow class for the first element too:

    Fully degradable with current manager.