From 2a0a0287d47bd51eef6d3369ca74c7f673e72b39 Mon Sep 17 00:00:00 2001 From: buttle Date: Tue, 10 Feb 2015 19:20:01 +0100 Subject: [PATCH 1/3] Added EVENT to homestubnav Changed menu->submenu(). if (! $menu->getItems()) then do nothing --- lib/homestubnav.php | 20 ++++++++++++-------- lib/menu.php | 2 ++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/homestubnav.php b/lib/homestubnav.php index 7dd6ae19a1..d22d1fd16c 100644 --- a/lib/homestubnav.php +++ b/lib/homestubnav.php @@ -49,13 +49,17 @@ class HomeStubNav extends Menu { function getItems() { - return array(array('top', - array(), - // TRANS: Menu item in personal group navigation menu. - _m('MENU','Home'), - // TRANS: Menu item title in personal group navigation menu. - // TRANS: %s is a username. - _('Back to top'), - 'nav_return_top')); + if (Event::handle('StartHomeStubNav', array(&$this->action))) { + return array(array('top', + array(), + // TRANS: Menu item in personal group navigation menu. + _m('MENU','Home'), + // TRANS: Menu item title in personal group navigation menu. + // TRANS: %s is a username. + _('Back to top'), + 'nav_return_top')); + Event::handle('EndHomeStubNav', array(&$this->action)); + } + return Null; } } diff --git a/lib/menu.php b/lib/menu.php index 27503aa06b..3d22ff4924 100644 --- a/lib/menu.php +++ b/lib/menu.php @@ -150,6 +150,8 @@ class Menu extends Widget function submenu($label, $menu) { + if(!$menu->getItems()) + return; $this->action->elementStart('li'); $this->action->element('h3', null, $label); $menu->show(); From d0347bb98fe97368b34cc82b69ce3a3284193362 Mon Sep 17 00:00:00 2001 From: buttle Date: Fri, 13 Feb 2015 16:26:41 +0100 Subject: [PATCH 2/3] Removing home stub if empty Added an Event HomeStubNavItems menu->subMenu() returns false if empty --- EVENTS.txt | 9 +++++++++ lib/homestubnav.php | 23 ++++++++++++----------- lib/menu.php | 5 +++-- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/EVENTS.txt b/EVENTS.txt index 197b8afe6f..66a86652e9 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -1463,3 +1463,12 @@ StartNotifyMentioned: During notice distribution, we send notifications (email, EndNotifyMentioned: During notice distribution, we send notifications (email, im...) to the profiles who were somehow mentioned. - $stored: Notice object that is being distributed. - $mentioned_ids: Array of profile IDs (not just for local users) who got mentioned by the notice. + +StartHomeStubNavItems: Go back Home nav items. Default includes just one item 'home' +- $action: action being executed (for output and params) +- $items: array of items in the nav + +EndHomeStubNavItems: +- $action: action being executed (for output and params) +- $items: array of items in the nav + diff --git a/lib/homestubnav.php b/lib/homestubnav.php index d22d1fd16c..64212f18aa 100644 --- a/lib/homestubnav.php +++ b/lib/homestubnav.php @@ -49,17 +49,18 @@ class HomeStubNav extends Menu { function getItems() { - if (Event::handle('StartHomeStubNav', array(&$this->action))) { - return array(array('top', - array(), - // TRANS: Menu item in personal group navigation menu. - _m('MENU','Home'), - // TRANS: Menu item title in personal group navigation menu. - // TRANS: %s is a username. - _('Back to top'), - 'nav_return_top')); - Event::handle('EndHomeStubNav', array(&$this->action)); + $items = array(); + if (Event::handle('StartHomeStubNavItems', array($this->action, &$items))) { + $items[] = array('top', + array(), + // TRANS: Menu item in personal group navigation menu. + _m('MENU','Home'), + // TRANS: Menu item title in personal group navigation menu. + // TRANS: %s is a username. + _('Back to top'), + 'nav_return_top'); + Event::handle('EndHomeStubNavItems', array($this->action, &$items)); } - return Null; + return $items; } } diff --git a/lib/menu.php b/lib/menu.php index 3d22ff4924..4baeb70d2f 100644 --- a/lib/menu.php +++ b/lib/menu.php @@ -150,8 +150,9 @@ class Menu extends Widget function submenu($label, $menu) { - if(!$menu->getItems()) - return; + if (empty($menu->getItems())){ + return false; + } $this->action->elementStart('li'); $this->action->element('h3', null, $label); $menu->show(); From 9a8ccbaef268474708009dde1635000b69e2df48 Mon Sep 17 00:00:00 2001 From: buttle Date: Fri, 13 Feb 2015 16:38:22 +0100 Subject: [PATCH 3/3] Call HomeStubNav instead of duplicating code adminpanelnav.php adds a homeStub but does not use the code created for the job. --- lib/adminpanelnav.php | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/lib/adminpanelnav.php b/lib/adminpanelnav.php index 93a4d36ebb..9044749181 100644 --- a/lib/adminpanelnav.php +++ b/lib/adminpanelnav.php @@ -59,24 +59,8 @@ class AdminPanelNav extends Menu $nickname = $user->nickname; $name = $user->getProfile()->getBestName(); - // Stub section w/ home link - $this->action->elementStart('ul'); - $this->action->elementStart('li'); - // TRANS: Header in administrator navigation panel. - $this->action->element('h3', null, _m('HEADER','Home')); - $this->action->elementStart('ul', 'nav'); - $this->out->menuItem(common_local_url('all', array('nickname' => - $nickname)), - // TRANS: Menu item in administrator navigation panel. - _m('MENU','Home'), - // TRANS: Menu item title in administrator navigation panel. - // TRANS: %s is a username. - sprintf(_('%s and friends'), $name), - $this->action == 'all', 'nav_timeline_personal'); - - $this->action->elementEnd('ul'); - $this->action->elementEnd('li'); - $this->action->elementEnd('ul'); + $stub = new HomeStubNav($this->action); + $this->submenu(_m('MENU','Home'), $stub); $this->action->elementStart('ul'); $this->action->elementStart('li');