Skip to content

Commit

Permalink
fixing up nested menus
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Jul 6, 2012
1 parent 8a06bd3 commit ef0902e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions Core/Menus/Model/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ public function getMenu($type = null) {
private function __underscore(&$menu) {
$menu[$this->alias]['plugin'] = Inflector::underscore($menu[$this->alias]['plugin']);
$menu[$this->alias]['controller'] = substr(Inflector::underscore($menu[$this->alias]['controller']), 0, -11);
$menu[$this->alias]['params'] = (array)json_decode($menu[$this->alias]['params'], true);

if(!empty($menu['children'])) {
foreach($menu['children'] as &$child) {
Expand Down
31 changes: 18 additions & 13 deletions Core/Menus/View/Helper/MenuHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,18 @@ public function builDashboardLinks($plugins = array(), $type = null, $cache = tr
*
* @return a nice formated <ul> list
*/
public function nestedList($data = array(), $type = 'horizontal') {
public function nestedList($data = array(), $config = array()) {
if (empty($data)) {
$this->errors[] = 'There are no items to make the menu with';
return false;
}

$this->_menuData = '<ul class="pureCssMenu pureCssMenum0">';
$config = array_merge(
array('class' => null, 'id' => null),
$config
);

$this->_menuData = String::insert('<ul class=":class" id=":id">', $config);
foreach( $data as $k => $v ) {
$this->_menuLevel = 0;
$this->__buildDropdownMenu($v, 'MenuItem');
Expand Down Expand Up @@ -218,7 +223,7 @@ public function link($data, $config = array()) {
*
* @param array $data the data from the find
*
* @return array
* @return string|array
*/
public function url($data) {
if(empty($data['MenuItem'])) {
Expand All @@ -229,14 +234,16 @@ public function url($data) {
return $data['MenuItem']['link'];
}

unset($data['MenuItem']['params']['data-attr']);

$url = array_merge(
array(
'plugin' => $data['MenuItem']['plugin'],
'controller' => $data['MenuItem']['controller'],
'action' => $data['MenuItem']['action'],
//'prefix' => $data['MenuItem']['prefix'],
),
(array)json_decode($data['MenuItem']['params'], true)
$data['MenuItem']['params']
);

if($data['MenuItem']['force_backend']) {
Expand All @@ -258,7 +265,7 @@ public function url($data) {
*
* @return part of the formated tree.
*/
private function __buildDropdownMenu($array = array(), $model = '') {
private function __buildDropdownMenu($array = array(), $model = '', $config = array()) {
if (empty($array['MenuItem']) || $model = '') {
$this->errors[] = 'nothing passed to generate';
return false;
Expand All @@ -282,6 +289,7 @@ private function __buildDropdownMenu($array = array(), $model = '') {
$linkName = '<span>'.$linkName.'</span>';
}

$cssClass = 'pureCssMenui';
$class = 'pureCssMenui'.$suffix;
if($isSeperator) {
$class .= ' seperator';
Expand All @@ -291,12 +299,7 @@ private function __buildDropdownMenu($array = array(), $model = '') {
if(!$isSeperator) {
$menuLink = $this->url($array);

if($menuLink == $this->here || (is_array($menuLink) && ($menuLink['controller'] == $this->request->params['controller'] || $menuLink['plugin'] == $this->request->params['plugin']))) {
$currentCss = ' current';
$this->_currentCssDone = true;
}

if(!empty($currentCss) && $this->_currentCssDone === false && Router::url($menuLink) == $this->here) {
if($this->_currentCssDone === false && Router::url($menuLink) == $this->here) {
$currentCss = ' current';
$this->_currentCssDone = true;
}
Expand All @@ -305,8 +308,10 @@ private function __buildDropdownMenu($array = array(), $model = '') {
$linkName,
InfinitasRouter::url($menuLink),
array(
'class' => 'pureCssMenui'.$suffix.$currentCss,
'escape' => false
'class' => String::insert(':subClass:suffix:currentCss', array('subClass' => $cssClass, 'suffix' => $suffix, 'currentCss' => $currentCss)),
'escape' => false,
'data-description' => !empty($array['MenuItem']['params']['data-attr']['description']) ? $array['MenuItem']['params']['data-attr']['description'] : '',
'target' => is_string($menuLink) && !in_array($menuLink{0}, array('/', '#')) ? '_blank' : '_self'
)
);

Expand Down

0 comments on commit ef0902e

Please sign in to comment.