Skip to content

Commit

Permalink
Refs #4202 Menu refactor GO. This one is tricky...
Browse files Browse the repository at this point in the history
  • Loading branch information
mattab committed Oct 9, 2013
1 parent dd3b749 commit e9817e9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 195 deletions.
30 changes: 22 additions & 8 deletions core/Menu/Admin.php → core/Menu/MenuAdmin.php
Expand Up @@ -15,12 +15,12 @@
/**
* @package Piwik_Menu
*/
class Admin extends MenuAbstract
class MenuAdmin extends MenuAbstract
{
static private $instance = null;

/**
* @return \Piwik\Menu\Admin
* @return \Piwik\Menu\MenuAdmin
*/
static public function getInstance()
{
Expand All @@ -31,11 +31,25 @@ static public function getInstance()
}

/**
* Triggers the Menu.Admin.addItems hook and returns the menu.
* Adds a new AdminMenu entry.
*
* @param string $adminMenuName
* @param string $url
* @param boolean $displayedForCurrentUser
* @param int $order
* @api
*/
public static function addEntry($adminMenuName, $url, $displayedForCurrentUser = true, $order = 20)
{
self::getInstance()->add('General_Settings', 'General_Settings', $adminMenuName, $url, $displayedForCurrentUser, $order);
}

/**
* Triggers the Menu.MenuAdmin.addItems hook and returns the admin menu.
*
* @return Array
*/
public function get()
public function getMenu()
{
if (!$this->menu) {

Expand All @@ -49,7 +63,7 @@ public function get()
* ```
* public function addMenuItems()
* {
* Piwik_AddAdminSubMenu(
* \Piwik\Menu\MenuAdmin::getInstance()->add(
* 'MenuName',
* 'SubmenuName',
* array('module' => 'MyPlugin', 'action' => 'index'),
Expand All @@ -59,9 +73,9 @@ public function get()
* }
* ```
*/
Piwik::postEvent('Menu.Admin.addItems');
Piwik::postEvent('Menu.MenuAdmin.addItems');
}
return parent::get();
return parent::getMenu();
}

/**
Expand All @@ -71,7 +85,7 @@ public function get()
*/
function getCurrentAdminMenuName()
{
$menu = Piwik_GetAdminMenu();
$menu = \Piwik\Menu\MenuAdmin::getInstance();
$currentModule = Piwik::getModule();
$currentAction = Piwik::getAction();
foreach ($menu as $submenu) {
Expand Down
10 changes: 5 additions & 5 deletions core/Menu/Main.php → core/Menu/MenuMain.php
Expand Up @@ -15,7 +15,7 @@
/**
* @package Piwik_Menu
*/
class Main extends MenuAbstract
class MenuMain extends MenuAbstract
{
static private $instance = null;

Expand All @@ -38,7 +38,7 @@ static public function getInstance()
*/
public function isUrlFound($url)
{
$menu = Main::getInstance()->get();
$menu = MenuMain::getInstance()->getMenu();

foreach ($menu as $subMenus) {
foreach ($subMenus as $subMenuName => $menuUrl) {
Expand All @@ -55,7 +55,7 @@ public function isUrlFound($url)
*
* @return Array
*/
public function get()
public function getMenu()
{
// We trigger the Event only once!
if (!$this->menu) {
Expand All @@ -70,7 +70,7 @@ public function get()
* ```
* public function addMenuItems()
* {
* Piwik_AddMenu(
* \Piwik\Menu\Main::getInstance()->add(
* 'CustomMenuName',
* 'CustomSubmenuName',
* array('module' => 'MyPlugin', 'action' => 'index'),
Expand All @@ -82,7 +82,7 @@ public function get()
*/
Piwik::postEvent('Menu.Reporting.addItems');
}
return parent::get();
return parent::getMenu();
}
}

12 changes: 6 additions & 6 deletions core/Menu/Top.php → core/Menu/MenuTop.php
Expand Up @@ -15,12 +15,12 @@
/**
* @package Piwik_Menu
*/
class Top extends MenuAbstract
class MenuTop extends MenuAbstract
{
static private $instance = null;

/**
* @return \Piwik\Menu\Top
* @return \Piwik\Menu\MenuTop
*/
static public function getInstance()
{
Expand Down Expand Up @@ -52,11 +52,11 @@ public function addHtml($menuName, $data, $displayedForCurrentUser, $order, $too
}

/**
* Triggers the Menu.Top.addItems hook and returns the menu.
* Triggers the Menu.MenuTop.addItems hook and returns the menu.
*
* @return Array
*/
public function get()
public function getMenu()
{
if (!$this->menu) {

Expand All @@ -80,8 +80,8 @@ public function get()
* }
* ```
*/
Piwik::postEvent('Menu.Top.addItems');
Piwik::postEvent('Menu.MenuTop.addItems');
}
return parent::get();
return parent::getMenu();
}
}
176 changes: 0 additions & 176 deletions core/functions.php

This file was deleted.

0 comments on commit e9817e9

Please sign in to comment.