Skip to content

Commit

Permalink
adding helper method for bootstrap menus and some adjustments to the …
Browse files Browse the repository at this point in the history
…admin index
  • Loading branch information
dogmatic69 committed Nov 21, 2012
1 parent 865f58e commit ab5f2f5
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
55 changes: 55 additions & 0 deletions Core/Menus/View/Helper/MenuHelper.php
Expand Up @@ -157,6 +157,61 @@ public function builDashboardLinks($plugins = array(), $type = null, $cache = tr
return $return;
}

public function bootstrapNav($menus, $ulOptions = array(), $child = false) {
foreach($menus as &$menu) {
$ulOptions = array(
'class' => 'nav'
);
$linkOptions = array(
'escape' => false
);
$hasChildren = !empty($menu['children']);

if($child && !$hasChildren) {
$ulOptions = array(
'class' => 'dropdown-menu'
);
}

$caret = null;
if($hasChildren) {
$linkOptions = array_merge(array(
'class' => 'dropdown-toggle',
'data-toggle' => 'dropdown'
), $linkOptions);
$caret = $this->Html->tag('b', '', array('class' => 'caret'));
}
$url = $this->url($menu);
if($menu['MenuItem']['name'] == '--') {
$menu['MenuItem']['name'] = $this->Html->tag('li', '', array('class' => 'divider'));
$hasChildren = false;
} else if($menu['MenuItem']['class'] == 'nav-header') {
$menu['MenuItem']['name'] = $this->Html->tag('li', $menu['MenuItem']['name'], array('class' => 'nav-header'));
} else {
$menu['MenuItem']['name'] = $this->Html->link($menu['MenuItem']['name'] . $caret, $url, $linkOptions);
}

if($hasChildren) {
$menu['MenuItem']['name'] .= self::bootstrapNav($menu['children'], array(), true);
}

$menu = $this->Html->tag('li', $menu['MenuItem']['name'], array(
'class' => array(
$this->here == $url ? 'active' : null,
$hasChildren ? 'dropdown' : null
)
));
}

$menus = $this->Html->tag('ul', implode('', $menus), $ulOptions);
if($child) {
return $menus;
}
return $this->Html->tag('div', $menus, array(
'class' => 'nav-collapse collapse'
));
}

/**
* Create nested list menu.
*
Expand Down
18 changes: 14 additions & 4 deletions Core/Menus/View/MenuItems/admin_index.ctp
Expand Up @@ -65,10 +65,20 @@
echo '<b>', str_repeat('- ', $paths-1), ' |</b> ';
}

echo $this->Html->link(
$menuItem['MenuItem']['name'] == '--' ? __('Seperator' ) : Inflector::humanize($menuItem['MenuItem']['name']),
array('action' => 'edit', $menuItem['MenuItem']['id'])
);
if($menuItem['MenuItem']['name'] == '--') {
$menuItem['MenuItem']['name'] = $this->Html->tag('span', __d('menus', 'Separator'), array(
'class' => 'label'
));
}
if($menuItem['MenuItem']['class'] == 'nav-header') {
$menuItem['MenuItem']['name'] = $this->Html->tag('span', $menuItem['MenuItem']['name'], array(
'class' => 'label label-info'
));
}
echo $this->Html->link($menuItem['MenuItem']['name'], array(
'action' => 'edit',
$menuItem['MenuItem']['id']
), array('escape' => false));
?>&nbsp;
</td>
<td><?php echo Inflector::humanize($menuItem['Menu']['name']); ?>&nbsp;</td>
Expand Down

0 comments on commit ab5f2f5

Please sign in to comment.