diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-09-06 14:16:37 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-09-06 14:16:37 +0400 |
commit | eee6ed99cf522e4e65df6618f5cd919a18da481b (patch) | |
tree | 5e7b017e408a9f9597868227919182db1f8c66f5 | |
parent | 099c969cb987607437c6b7beabcd4e6883e5998d (diff) |
refs #6140 easier way to define URLs for menu items and introducing a method to addItem without boolean parameter
31 files changed, 232 insertions, 103 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c6720e9fc..bec2be0ab6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ This is a changelog for Piwik platform developers. All changes for our HTTP API's, Plugins, Themes, etc will be listed here. +## Piwik 2.7.0 + +### Deprecations +* The `Piwik\Menu\MenuAbstract::add()` method is deprecated in favor of `addItem()`. Read more about this here: [#6140](https://github.com/piwik/piwik/issues/6140). We do not plan to remove the deprecated method before Piwik 3.0. + +### New APIs +* It is now easier to generate the URL for a menu item see [#6140](https://github.com/piwik/piwik/issues/6140), [urlForDefaultAction()](http://developer.piwik.org/api-reference/Piwik/Menu/MenuAbstract#urlfordefaultaction):, [urlForAction()](http://developer.piwik.org/api-reference/Piwik/Menu/MenuAbstract#urlforaction), [urlForModuleAction()](http://developer.piwik.org/api-reference/Piwik/Menu/MenuAbstract#urlformoduleaction) + + ## Piwik 2.6.0 ### New features diff --git a/core/Menu/MenuAbstract.php b/core/Menu/MenuAbstract.php index 2ccf6fda28..1fe1152c98 100644 --- a/core/Menu/MenuAbstract.php +++ b/core/Menu/MenuAbstract.php @@ -77,16 +77,32 @@ abstract class MenuAbstract extends Singleton * current user. If false, the entry will not be added. * @param int $order The order hint. * @param bool|string $tooltip An optional tooltip to display or false to display the tooltip. - * @api + * + * @deprecated since 2.7.0 Use {@link addItem() instead}. Method will be removed in Piwik 3.0 */ public function add($menuName, $subMenuName, $url, $displayedForCurrentUser = true, $order = 50, $tooltip = false) { if (!$displayedForCurrentUser) { - // TODO this parameter should be removed and instead menu items should be only added if it is supposed to be - // displayed. Won't do it now to stay backward compatible. For Piwik 3.0 we should do it. return; } + $this->addItem($menuName, $subMenuName, $url, $order, $tooltip); + } + + /** + * Adds a new entry to the menu. + * + * @param string $menuName The menu's category name. Can be a translation token. + * @param string $subMenuName The menu item's name. Can be a translation token. + * @param string|array $url The URL the admin menu entry should link to, or an array of query parameters + * that can be used to build the URL. + * @param int $order The order hint. + * @param bool|string $tooltip An optional tooltip to display or false to display the tooltip. + * @since 2.7.0 + * @api + */ + public function addItem($menuName, $subMenuName, $url, $order = 50, $tooltip = false) + { // make sure the idSite value used is numeric (hack-y fix for #3426) if (!is_numeric(Common::getRequestVar('idSite', false))) { $idSites = API::getInstance()->getSitesIdWithAtLeastViewAccess(); diff --git a/core/Plugin/Menu.php b/core/Plugin/Menu.php index 9f7240b1f3..b6892a79f2 100644 --- a/core/Plugin/Menu.php +++ b/core/Plugin/Menu.php @@ -12,6 +12,7 @@ use Piwik\Menu\MenuAdmin; use Piwik\Menu\MenuReporting; use Piwik\Menu\MenuTop; use Piwik\Menu\MenuUser; +use Piwik\Plugin\Manager as PluginManager; /** * Base class of all plugin menu providers. Plugins that define their own menu items can extend this class to easily @@ -27,6 +28,102 @@ use Piwik\Menu\MenuUser; */ class Menu { + protected $module = ''; + + /** + * @ignore + */ + public function __construct() + { + $this->module = $this->getModule(); + } + + private function getModule() + { + $className = get_class($this); + $className = explode('\\', $className); + + return $className[2]; + } + + /** + * Generates a URL for the default action of the plugin controller. + * + * Example: + * ``` + * $menu->addItem('UI Framework', '', $this->urlForDefaultAction(), $orderId = 30); + * // will add a menu item that leads to the default action of the plugin controller when a user clicks on it. + * // The default action is usually the `index` action - meaning the `index()` method the controller - + * // but the default action can be customized within a controller + * ``` + * + * @param array $additionalParams Optional URL parameters that will be appended to the URL + * @return array + * + * @since 2.7.0 + * @api + */ + protected function urlForDefaultAction($additionalParams = array()) + { + $params = (array) $additionalParams; + $params['action'] = ''; + $params['module'] = $this->module; + + return $params; + } + + /** + * Generates a URL for the given action. In your plugin controller you have to create a method with the same name + * as this method will be executed when a user clicks on the menu item. If you want to generate a URL for the + * action of another module, meaning not your plugin, you should use the method {@link urlForModuleAction()}. + * + * @param string $controllerAction The name of the action that should be executed within your controller + * @param array $additionalParams Optional URL parameters that will be appended to the URL + * @return array + * + * @since 2.7.0 + * @api + */ + protected function urlForAction($controllerAction, $additionalParams = array()) + { + $params = (array) $additionalParams; + $params['action'] = $controllerAction; + $params['module'] = $this->module; + + return $params; + } + + /** + * Generates a URL for the given action of the given module. We usually do not recommend to use this method as you + * should make sure the method of that module actually exists. If the plugin owner of that module changes the method + * in a future version your link might no longer work. If you want to link to an action of your controller use the + * method {@link urlForAction()}. Note: We will generate a link only if the given module is installed and activated. + * + * @param string $module The name of the module/plugin the action belongs to. The module name is case sensitive. + * @param string $controllerAction The name of the action that should be executed within your controller + * @param array $additionalParams Optional URL parameters that will be appended to the URL + * @return array|null Returns null if the given module is either not installed or not activated. Returns the URL + * to the given module action otherwise. + * + * @since 2.7.0 + * // not API for now + */ + protected function urlForModuleAction($module, $controllerAction, $additionalParams = array()) + { + $pluginManager = PluginManager::getInstance(); + + if (!$pluginManager->isPluginLoaded($module) || + !$pluginManager->isPluginActivated($module)) { + return null; + } + + $params = (array) $additionalParams; + $params['action'] = $controllerAction; + $params['module'] = $module; + + return $params; + } + /** * Configures the reporting menu which should only contain links to reports of a specific site such as * "Search Engines", "Page Titles" or "Locations & Provider". diff --git a/plugins/API/Menu.php b/plugins/API/Menu.php index 0020ecf1c4..b01c686ac0 100644 --- a/plugins/API/Menu.php +++ b/plugins/API/Menu.php @@ -26,7 +26,7 @@ class Menu extends \Piwik\Plugin\Menu public function configureUserMenu(MenuUser $menu) { - $apiUrlParams = array('module' => 'API', 'action' => 'listAllAPI', 'segment' => false); + $apiUrlParams = $this->urlForAction('listAllAPI', array('segment' => false)); $tooltip = Piwik::translate('API_TopLinkTooltip'); $menu->addPlatformItem('General_API', $apiUrlParams, 6, $tooltip); @@ -45,8 +45,14 @@ class Menu extends \Piwik\Plugin\Menu $ua = new OperatingSystem($_SERVER['HTTP_USER_AGENT']); $ua->setCache(new DeviceDetectorCache('tracker', 86400)); $parsedOS = $ua->parse(); + if (!empty($parsedOS['short_name']) && in_array($parsedOS['short_name'], array(self::DD_SHORT_NAME_ANDROID, self::DD_SHORT_NAME_IOS))) { - $menu->add('Piwik Mobile App', null, array('module' => 'Proxy', 'action' => 'redirect', 'url' => 'http://piwik.org/mobile/'), true, 4); + + $url = $this->urlForModuleAction('Proxy', 'redirect', array('url' => 'http://piwik.org/mobile/')); + + if ($url) { + $menu->addItem('Piwik Mobile App', null, $url, 4); + } } } diff --git a/plugins/Actions/Menu.php b/plugins/Actions/Menu.php index 8804fabe0d..e9ce436b75 100644 --- a/plugins/Actions/Menu.php +++ b/plugins/Actions/Menu.php @@ -14,16 +14,11 @@ class Menu extends \Piwik\Plugin\Menu { public function configureReportingMenu(MenuReporting $menu) { - $urlParams = array( - 'module' => 'Actions', - 'action' => 'menuGetPageUrls' - ); - - $menu->addActionsItem('', $urlParams, 15); + $menu->addActionsItem('', $this->urlForAction('menuGetPageUrls'), 15); $actions = new Actions(); if ($actions->isSiteSearchEnabled()) { - $menu->addActionsItem('Actions_SubmenuSitesearch', array('module' => 'Actions', 'action' => 'indexSiteSearch'), 5); + $menu->addActionsItem('Actions_SubmenuSitesearch', $this->urlForAction('indexSiteSearch'), 5); } } diff --git a/plugins/CoreAdminHome/Menu.php b/plugins/CoreAdminHome/Menu.php index 368a470fff..7926ff9cf5 100644 --- a/plugins/CoreAdminHome/Menu.php +++ b/plugins/CoreAdminHome/Menu.php @@ -27,16 +27,16 @@ class Menu extends \Piwik\Plugin\Menu $menu->addDevelopmentItem(null, "", $order = 15); $menu->addSettingsItem('CoreAdminHome_MenuGeneralSettings', - array('module' => 'CoreAdminHome', 'action' => 'generalSettings'), + $this->urlForAction('generalSettings'), $order = 6); $menu->addManageItem('CoreAdminHome_TrackingCode', - array('module' => 'CoreAdminHome', 'action' => 'trackingCodeGenerator'), + $this->urlForAction('trackingCodeGenerator'), $order = 4); } if (SettingsManager::hasPluginsSettingsForCurrentUser()) { $menu->addSettingsItem('CoreAdminHome_PluginSettings', - array('module' => 'CoreAdminHome', 'action' => 'pluginSettings'), + $this->urlForAction('pluginSettings'), $order = 7); } } diff --git a/plugins/CorePluginsAdmin/Menu.php b/plugins/CorePluginsAdmin/Menu.php index cd056720d5..8279afcc73 100644 --- a/plugins/CorePluginsAdmin/Menu.php +++ b/plugins/CorePluginsAdmin/Menu.php @@ -46,16 +46,16 @@ class Menu extends \Piwik\Plugin\Menu if ($hasSuperUserAcess) { $menu->addPlatformItem(Piwik::translate('General_Plugins') . $pluginsUpdateMessage, - array('module' => 'CorePluginsAdmin', 'action' => 'plugins', 'activated' => ''), + $this->urlForAction('plugins', array('activated' => '')), $order = 1); $menu->addPlatformItem(Piwik::translate('CorePluginsAdmin_Themes') . $themesUpdateMessage, - array('module' => 'CorePluginsAdmin', 'action' => 'themes', 'activated' => ''), + $this->urlForAction('themes', array('activated' => '')), $order = 3); } if ($this->isAllowedToSeeMarketPlace()) { $menu->addPlatformItem('CorePluginsAdmin_Marketplace', - array('module' => 'CorePluginsAdmin', 'action' => 'extend', 'activated' => ''), + $this->urlForAction('extend', array('activated' => '')), $order = 5); } @@ -73,8 +73,8 @@ class Menu extends \Piwik\Plugin\Menu { if ($this->isAllowedToSeeMarketPlace()) { $menu->addPlatformItem('CorePluginsAdmin_Marketplace', - array('module' => 'CorePluginsAdmin', 'action' => 'browsePlugins', 'activated' => ''), - $order = 5); + $this->urlForAction('browsePlugins', array('activated' => '')), + $order = 5); } } } diff --git a/plugins/DBStats/Menu.php b/plugins/DBStats/Menu.php index 50f7b8a047..a52b9bd2fd 100644 --- a/plugins/DBStats/Menu.php +++ b/plugins/DBStats/Menu.php @@ -19,7 +19,7 @@ class Menu extends \Piwik\Plugin\Menu { if (Piwik::hasUserSuperUserAccess()) { $menu->addDiagnosticItem('DBStats_DatabaseUsage', - array('module' => 'DBStats', 'action' => 'index'), + $this->urlForAction('index'), $order = 6); } } diff --git a/plugins/Dashboard/Menu.php b/plugins/Dashboard/Menu.php index 2549021fc7..2ee0521623 100644 --- a/plugins/Dashboard/Menu.php +++ b/plugins/Dashboard/Menu.php @@ -21,7 +21,7 @@ class Menu extends \Piwik\Plugin\Menu { public function configureReportingMenu(MenuReporting $menu) { - $menu->add('Dashboard_Dashboard', '', array('module' => 'Dashboard', 'action' => 'embeddedIndex', 'idDashboard' => 1), true, 5); + $menu->addItem('Dashboard_Dashboard', '', $this->urlForAction('embeddedIndex', array('idDashboard' => 1)), 5); if (!Piwik::isUserIsAnonymous()) { $login = Piwik::getCurrentUserLogin(); @@ -31,7 +31,7 @@ class Menu extends \Piwik\Plugin\Menu $pos = 0; foreach ($dashboards as $dashboard) { - $menu->add('Dashboard_Dashboard', $dashboard['name'], array('module' => 'Dashboard', 'action' => 'embeddedIndex', 'idDashboard' => $dashboard['iddashboard']), true, $pos); + $menu->addItem('Dashboard_Dashboard', $dashboard['name'], $this->urlForAction('embeddedIndex', array('idDashboard' => $dashboard['iddashboard'])), $pos); $pos++; } } @@ -44,13 +44,9 @@ class Menu extends \Piwik\Plugin\Menu $tooltip = Piwik::translate('Dashboard_TopLinkTooltip', Site::getNameFor($idSite)); - $urlParams = array( - 'module' => 'CoreHome', - 'action' => 'index', - 'idSite' => $idSite, - ); + $urlParams = $this->urlForModuleAction('CoreHome', 'index', array('idSite' => $idSite)) ; - $menu->add('Dashboard_Dashboard', null, $urlParams, true, 1, $tooltip); + $menu->addItem('Dashboard_Dashboard', null, $urlParams, 1, $tooltip); } } diff --git a/plugins/DevicesDetection/Menu.php b/plugins/DevicesDetection/Menu.php index e37c62e75f..797f988624 100644 --- a/plugins/DevicesDetection/Menu.php +++ b/plugins/DevicesDetection/Menu.php @@ -20,13 +20,13 @@ class Menu extends \Piwik\Plugin\Menu { if (Piwik::isUserHasSomeAdminAccess()) { $menu->addDiagnosticItem('DevicesDetection_DeviceDetection', - array('module' => 'DevicesDetection', 'action' => 'deviceDetection'), + $this->urlForAction('deviceDetection'), $order = 40); } } public function configureReportingMenu(MenuReporting $menu) { - $menu->addVisitorsItem('DevicesDetection_submenu', array('module' => 'DevicesDetection', 'action' => 'index')); + $menu->addVisitorsItem('DevicesDetection_submenu', $this->urlForAction('index')); } } diff --git a/plugins/Events/Menu.php b/plugins/Events/Menu.php index 01c60cabe6..440a35978e 100644 --- a/plugins/Events/Menu.php +++ b/plugins/Events/Menu.php @@ -16,6 +16,6 @@ class Menu extends \Piwik\Plugin\Menu { public function configureReportingMenu(MenuReporting $menu) { - $menu->addActionsItem('Events_Events', array('module' => 'Events', 'action' => 'index'), 30); + $menu->addActionsItem('Events_Events', $this->urlForAction('index'), 30); } } diff --git a/plugins/ExamplePlugin/Menu.php b/plugins/ExamplePlugin/Menu.php index 2a3ed266f2..b1fcde4eea 100644 --- a/plugins/ExamplePlugin/Menu.php +++ b/plugins/ExamplePlugin/Menu.php @@ -22,34 +22,37 @@ class Menu extends \Piwik\Plugin\Menu { public function configureReportingMenu(MenuReporting $menu) { - // with custom category 'UI Framework' - // $menu->add('UI Framework', '', array('module' => 'ExamplePlugin', 'action' => ''), true, $orderId = 30); - // $menu->add('UI Framework', 'Report 1', array('module' => 'ExamplePlugin', 'action' => 'report1'), true, $orderId = 30); - // or reusing an existing category - // $menu->addVisitorsItem('Report 1', array('module' => 'ExamplePlugin', 'action' => 'report1'), $orderId = 30); - // $menu->addActionsItem('Report 1', array('module' => 'ExamplePlugin', 'action' => 'report1'), $orderId = 30); + // reuse an existing category + // $menu->addVisitorsItem('Report 1', $this->urlForAction('report1'), $orderId = 30); + // $menu->addActionsItem('Report 1', $this->urlForAction('report1'), $orderId = 30); + + // or create a custom category 'UI Framework' + // $menu->addItem('UI Framework', '', $this->urlForDefaultAction(), $orderId = 30); + // $menu->addItem('UI Framework', 'Report 1', $this->urlForAction('report1'), $orderId = 30); } public function configureAdminMenu(MenuAdmin $menu) { - // with custom category - // $menu->add('General_Settings', 'My Admin Item', array('module' => 'ExamplePlugin', 'action' => ''), true, $orderId = 30); - // or reusing an existing category - // $menu->addSettingsItem('My Admin Item', array('module' => 'ExamplePlugin', 'action' => ''), $orderId = 30); - // $menu->addPlatformItem('My Admin Item', array('module' => 'ExamplePlugin', 'action' => ''), $orderId = 30); + // reuse an existing category + // $menu->addSettingsItem('My Admin Item', $this->urlForDefaultAction(), $orderId = 30); + // $menu->addPlatformItem('My Admin Item', $this->urlForDefaultAction(), $orderId = 30); + + // or create a custom category + // $menu->addItem('General_Settings', 'My Admin Item', $this->urlForDefaultAction(), $orderId = 30); } public function configureTopMenu(MenuTop $menu) { - // $menu->add('My Top Item', null, array('module' => 'ExamplePlugin', 'action' => ''), true, $orderId = 30); + // $menu->addItem('My Top Item', null, $this->urlForDefaultAction(), $orderId = 30); } public function configureUserMenu(MenuUser $menu) { - // with custom category - // $menu->add('CoreAdminHome_MenuManage', 'My User Item', array('module' => 'ExamplePlugin', 'action' => ''), true, $orderId = 30); - // or reusing an existing category - // $menu->addManageItem('My User Item', array('module' => 'ExamplePlugin', 'action' => ''), $orderId = 30); - // $menu->addPlatformItem('My User Item', array('module' => 'ExamplePlugin', 'action' => ''), $orderId = 30); + // reuse an existing category + // $menu->addManageItem('My User Item', $this->urlForDefaultAction(), $orderId = 30); + // $menu->addPlatformItem('My User Item', $this->urlForDefaultAction(), $orderId = 30); + + // or create a custom category + // $menu->addItem('CoreAdminHome_MenuManage', 'My User Item', $this->urlForDefaultAction(), $orderId = 30); } } diff --git a/plugins/ExampleUI/Menu.php b/plugins/ExampleUI/Menu.php index 8b5f1bcfea..d608968edf 100644 --- a/plugins/ExampleUI/Menu.php +++ b/plugins/ExampleUI/Menu.php @@ -18,7 +18,7 @@ class Menu extends \Piwik\Plugin\Menu { public function configureReportingMenu(MenuReporting $menu) { - $menu->add('UI Framework', '', array('module' => 'ExampleUI', 'action' => 'dataTables'), true, 30); + $menu->addItem('UI Framework', '', array('module' => 'ExampleUI', 'action' => 'dataTables'), 30); $this->addSubMenu($menu, 'Data tables', 'dataTables', 1); $this->addSubMenu($menu, 'Bar graph', 'barGraph', 2); @@ -34,12 +34,11 @@ class Menu extends \Piwik\Plugin\Menu public function configureUserMenu(MenuUser $menu) { - $urlParams = array('module' => 'ExampleUI', 'action' => 'notifications'); - $menu->addPlatformItem('UI Notifications', $urlParams, $order = 3); + $menu->addPlatformItem('UI Notifications', $this->urlForAction('notifications'), $order = 3); } private function addSubMenu(MenuReporting $menu, $subMenu, $action, $order) { - $menu->add('UI Framework', $subMenu, array('module' => 'ExampleUI', 'action' => $action), true, $order); + $menu->addItem('UI Framework', $subMenu, $this->urlForAction($action), $order); } } diff --git a/plugins/Feedback/Menu.php b/plugins/Feedback/Menu.php index aa1156bc52..acfd55dab1 100644 --- a/plugins/Feedback/Menu.php +++ b/plugins/Feedback/Menu.php @@ -15,11 +15,10 @@ class Menu extends \Piwik\Plugin\Menu { public function configureUserMenu(MenuUser $menu) { - $menu->add( + $menu->addItem( 'General_Help', null, - array('module' => 'Feedback', 'action' => 'index', 'segment' => false), - true, + $this->urlForAction('index', array('segment' => false)), $order = 99, $tooltip = Piwik::translate('Feedback_TopLinkTooltip') ); diff --git a/plugins/Goals/Menu.php b/plugins/Goals/Menu.php index 62608d8729..46b394b067 100644 --- a/plugins/Goals/Menu.php +++ b/plugins/Goals/Menu.php @@ -29,41 +29,40 @@ class Menu extends \Piwik\Plugin\Menu $site = new Site($idSite); if (count($goals) == 0) { + $action = $site->isEcommerceEnabled() ? 'ecommerceReport' : 'addNewGoal'; + $url = $this->urlForAction($action, array( + 'idGoal' => ($site->isEcommerceEnabled() ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER : null + ))); - $menu->add($mainGoalMenu, '', array('module' => 'Goals', - 'action' => ($site->isEcommerceEnabled() ? 'ecommerceReport' : 'addNewGoal'), - 'idGoal' => ($site->isEcommerceEnabled() ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER : null)), - true, - 25); + $menu->addItem($mainGoalMenu, '', $url, 25); if ($site->isEcommerceEnabled()) { - $menu->add($mainGoalMenu, 'Goals_Ecommerce', array('module' => 'Goals', 'action' => 'ecommerceReport', 'idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER), true, 1); + $menu->addItem($mainGoalMenu, 'Goals_Ecommerce', $this->urlForAction('ecommerceReport', array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER)), 1); } - $menu->add($mainGoalMenu, 'Goals_AddNewGoal', array('module' => 'Goals', 'action' => 'addNewGoal')); + $menu->addItem($mainGoalMenu, 'Goals_AddNewGoal', $this->urlForAction('addNewGoal')); } else { - $menu->add($mainGoalMenu, '', array('module' => 'Goals', - 'action' => ($site->isEcommerceEnabled() ? 'ecommerceReport' : 'index'), - 'idGoal' => ($site->isEcommerceEnabled() ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER : null)), - true, - 25); + $action = $site->isEcommerceEnabled() ? 'ecommerceReport' : 'index'; + $url = $this->urlForAction($action, array('idGoal' => ($site->isEcommerceEnabled() ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER : null))); + + $menu->addItem($mainGoalMenu, '', $url, 25); if ($site->isEcommerceEnabled()) { - $menu->add($mainGoalMenu, 'Goals_Ecommerce', array('module' => 'Goals', 'action' => 'ecommerceReport', 'idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER), true, 1); + $menu->addItem($mainGoalMenu, 'Goals_Ecommerce', $this->urlForAction('ecommerceReport', array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER)), 1); } - $menu->add($mainGoalMenu, 'Goals_GoalsOverview', array('module' => 'Goals', 'action' => 'index'), true, 2); + $menu->addItem($mainGoalMenu, 'Goals_GoalsOverview', array('module' => 'Goals', 'action' => 'index'), 2); $group = new Group(); foreach ($goals as $goal) { $subMenuName = str_replace('%', '%%', Translate::clean($goal['name'])); - $params = array('module' => 'Goals', 'action' => 'goalReport', 'idGoal' => $goal['idgoal']); + $params = $this->urlForAction('goalReport', array('idGoal' => $goal['idgoal'])); $tooltip = sprintf('%s (id = %d)', $subMenuName, $goal['idgoal']); if (count($goals) <= 3) { - $menu->add($mainGoalMenu, $subMenuName, $params, true, 50, $tooltip); + $menu->addItem($mainGoalMenu, $subMenuName, $params, 50, $tooltip); } else { $group->add($subMenuName, $params, $tooltip); } diff --git a/plugins/Installation/Menu.php b/plugins/Installation/Menu.php index 7ae25c8d79..fd57fab75c 100644 --- a/plugins/Installation/Menu.php +++ b/plugins/Installation/Menu.php @@ -17,7 +17,7 @@ class Menu extends \Piwik\Plugin\Menu { if (Piwik::hasUserSuperUserAccess()) { $menu->addSettingsItem('Installation_SystemCheck', - array('module' => 'Installation', 'action' => 'systemCheckPage'), + $this->urlForAction('systemCheckPage'), $order = 15); } } diff --git a/plugins/LanguagesManager/Menu.php b/plugins/LanguagesManager/Menu.php index 1b53892a94..a51250d944 100644 --- a/plugins/LanguagesManager/Menu.php +++ b/plugins/LanguagesManager/Menu.php @@ -28,7 +28,7 @@ class Menu extends \Piwik\Plugin\Menu { if (Development::isEnabled() && Piwik::isUserHasSomeAdminAccess()) { $menu->addDevelopmentItem('LanguagesManager_TranslationSearch', - array('module' => 'LanguagesManager', 'action' => 'searchTranslation')); + $this->urlForAction('searchTranslation')); } } } diff --git a/plugins/MobileMessaging/Menu.php b/plugins/MobileMessaging/Menu.php index 4dea3c329d..e810e99744 100644 --- a/plugins/MobileMessaging/Menu.php +++ b/plugins/MobileMessaging/Menu.php @@ -14,10 +14,6 @@ class Menu extends \Piwik\Plugin\Menu { public function configureAdminMenu(MenuAdmin $menu) { - $menu->addSettingsItem( - 'MobileMessaging_SettingsMenu', - array('module' => 'MobileMessaging', 'action' => 'index'), - $order = 12 - ); + $menu->addSettingsItem('MobileMessaging_SettingsMenu', $this->urlForAction('index'), $order = 12); } } diff --git a/plugins/MultiSites/Menu.php b/plugins/MultiSites/Menu.php index 0cbee0d89b..5059cfc09d 100644 --- a/plugins/MultiSites/Menu.php +++ b/plugins/MultiSites/Menu.php @@ -15,7 +15,7 @@ class Menu extends \Piwik\Plugin\Menu { public function configureTopMenu(MenuTop $menu) { - $urlParams = array('module' => 'MultiSites', 'action' => 'index', 'segment' => false); + $urlParams = $this->urlForAction('index', array('segment' => false)); $tooltip = Piwik::translate('MultiSites_TopLinkTooltip'); $menu->add('General_MultiSitesSummary', null, $urlParams, true, 3, $tooltip); diff --git a/plugins/PrivacyManager/Menu.php b/plugins/PrivacyManager/Menu.php index 5eee77622c..33c7aa55a2 100644 --- a/plugins/PrivacyManager/Menu.php +++ b/plugins/PrivacyManager/Menu.php @@ -17,7 +17,7 @@ class Menu extends \Piwik\Plugin\Menu { if (Piwik::isUserHasSomeAdminAccess()) { $menu->addSettingsItem('PrivacyManager_MenuPrivacySettings', - array('module' => 'PrivacyManager', 'action' => 'privacySettings'), + $this->urlForAction('privacySettings'), $order = 7); } } diff --git a/plugins/Referrers/Menu.php b/plugins/Referrers/Menu.php index 60768d7c2f..835ae15f78 100644 --- a/plugins/Referrers/Menu.php +++ b/plugins/Referrers/Menu.php @@ -14,9 +14,9 @@ class Menu extends \Piwik\Plugin\Menu { public function configureReportingMenu(MenuReporting $menu) { - $menu->addReferrersItem('', array('module' => 'Referrers', 'action' => 'index'), 20); - $menu->addReferrersItem('General_Overview', array('module' => 'Referrers', 'action' => 'index'), 1); - $menu->addReferrersItem('Referrers_SubmenuSearchEngines', array('module' => 'Referrers', 'action' => 'getSearchEnginesAndKeywords'), 2); - $menu->addReferrersItem('Referrers_SubmenuWebsites', array('module' => 'Referrers', 'action' => 'indexWebsites'), 3); + $menu->addReferrersItem('', $this->urlForAction('index'), 20); + $menu->addReferrersItem('General_Overview', $this->urlForAction('index'), 1); + $menu->addReferrersItem('Referrers_SubmenuSearchEngines', $this->urlForAction('getSearchEnginesAndKeywords'), 2); + $menu->addReferrersItem('Referrers_SubmenuWebsites', $this->urlForAction('indexWebsites'), 3); } } diff --git a/plugins/ScheduledReports/Menu.php b/plugins/ScheduledReports/Menu.php index 26aafad2ad..6c0111ff23 100644 --- a/plugins/ScheduledReports/Menu.php +++ b/plugins/ScheduledReports/Menu.php @@ -24,10 +24,10 @@ class Menu extends \Piwik\Plugin\Menu \Piwik\Plugin\Manager::getInstance()->isPluginActivated('MobileMessaging') ? 'MobileMessaging_TopLinkTooltip' : 'ScheduledReports_TopLinkTooltip'); - $menu->addManageItem(null, array('module' => '', 'action' => '', 'segment' => false), 10); + $menu->addManageItem(null, $this->urlForDefaultAction(array('segment' => false)), 10); $menu->addManageItem( $this->getTopMenuTranslationKey(), - array('module' => 'ScheduledReports', 'action' => 'index', 'segment' => false), + $this->urlForAction('index', array('segment' => false)), 13, $tooltip ); diff --git a/plugins/SitesManager/Menu.php b/plugins/SitesManager/Menu.php index 017690f442..3f4d1b02ad 100644 --- a/plugins/SitesManager/Menu.php +++ b/plugins/SitesManager/Menu.php @@ -17,7 +17,7 @@ class Menu extends \Piwik\Plugin\Menu { if (Piwik::isUserHasSomeAdminAccess()) { $menu->addManageItem('SitesManager_Sites', - array('module' => 'SitesManager', 'action' => 'index'), + $this->urlForAction('index'), $order = 1); } } diff --git a/plugins/UserCountry/Menu.php b/plugins/UserCountry/Menu.php index 41e259a618..9305ab23fa 100644 --- a/plugins/UserCountry/Menu.php +++ b/plugins/UserCountry/Menu.php @@ -18,13 +18,13 @@ class Menu extends \Piwik\Plugin\Menu { if (UserCountry::isGeoLocationAdminEnabled() && Piwik::hasUserSuperUserAccess()) { $menu->addSettingsItem('UserCountry_Geolocation', - array('module' => 'UserCountry', 'action' => 'adminIndex'), + $this->urlForAction('adminIndex'), $order = 8); } } public function configureReportingMenu(MenuReporting $menu) { - $menu->addVisitorsItem('UserCountry_SubmenuLocations', array('module' => 'UserCountry', 'action' => 'index')); + $menu->addVisitorsItem('UserCountry_SubmenuLocations', $this->urlForAction('index')); } } diff --git a/plugins/UserCountryMap/Menu.php b/plugins/UserCountryMap/Menu.php index fa32a8f9b7..88108e3f4d 100644 --- a/plugins/UserCountryMap/Menu.php +++ b/plugins/UserCountryMap/Menu.php @@ -17,7 +17,7 @@ class Menu extends \Piwik\Plugin\Menu { if (PluginManager::getInstance()->isPluginActivated('UserCountry')) { $menu->addVisitorsItem('UserCountryMap_RealTimeMap', - array('module' => 'UserCountryMap', 'action' => 'realtimeWorldMap'), + $this->urlForAction('realtimeWorldMap'), $order = 70); } } diff --git a/plugins/UserSettings/Menu.php b/plugins/UserSettings/Menu.php index 5b442e5e09..c194ea20fb 100644 --- a/plugins/UserSettings/Menu.php +++ b/plugins/UserSettings/Menu.php @@ -14,6 +14,6 @@ class Menu extends \Piwik\Plugin\Menu { public function configureReportingMenu(MenuReporting $menu) { - $menu->addVisitorsItem('General_Settings', array('module' => 'UserSettings', 'action' => 'index')); + $menu->addVisitorsItem('General_Settings', $this->urlForAction('index')); } } diff --git a/plugins/UsersManager/Menu.php b/plugins/UsersManager/Menu.php index 494d09542c..8335d97305 100644 --- a/plugins/UsersManager/Menu.php +++ b/plugins/UsersManager/Menu.php @@ -16,12 +16,8 @@ class Menu extends \Piwik\Plugin\Menu public function configureAdminMenu(MenuAdmin $menu) { if (Piwik::isUserHasSomeAdminAccess()) { - $menu->addManageItem('UsersManager_MenuUsers', - array('module' => 'UsersManager', 'action' => 'index'), - $order = 2); - $menu->addManageItem('UsersManager_MenuUserSettings', - array('module' => 'UsersManager', 'action' => 'userSettings'), - $order = 3); + $menu->addManageItem('UsersManager_MenuUsers', $this->urlForAction('index'), $order = 2); + $menu->addManageItem('UsersManager_MenuUserSettings', $this->urlForAction('userSettings'), $order = 3); } } } diff --git a/plugins/VisitFrequency/Menu.php b/plugins/VisitFrequency/Menu.php index 8759cf751d..e858bd2f76 100644 --- a/plugins/VisitFrequency/Menu.php +++ b/plugins/VisitFrequency/Menu.php @@ -14,7 +14,6 @@ class Menu extends \Piwik\Plugin\Menu { public function configureReportingMenu(MenuReporting $menu) { - $menu->addVisitorsItem('VisitFrequency_SubmenuFrequency', - array('module' => 'VisitFrequency', 'action' => 'index'), $order = 55); + $menu->addVisitorsItem('VisitFrequency_SubmenuFrequency', $this->urlForAction('index'), $order = 55); } } diff --git a/plugins/VisitTime/Menu.php b/plugins/VisitTime/Menu.php index db221a4eda..ffa3a5b015 100644 --- a/plugins/VisitTime/Menu.php +++ b/plugins/VisitTime/Menu.php @@ -14,7 +14,6 @@ class Menu extends \Piwik\Plugin\Menu { public function configureReportingMenu(MenuReporting $menu) { - $menu->addVisitorsItem('VisitTime_SubmenuTimes', - array('module' => 'VisitTime', 'action' => 'index'), $order = 65); + $menu->addVisitorsItem('VisitTime_SubmenuTimes', $this->urlForAction('index'), $order = 65); } } diff --git a/plugins/Widgetize/Menu.php b/plugins/Widgetize/Menu.php index 954df309e5..f796faf57e 100644 --- a/plugins/Widgetize/Menu.php +++ b/plugins/Widgetize/Menu.php @@ -16,7 +16,7 @@ class Menu extends \Piwik\Plugin\Menu public function configureUserMenu(MenuUser $menu) { $tooltip = Piwik::translate('Widgetize_TopLinkTooltip'); - $urlParams = array('module' => 'Widgetize', 'action' => 'index', 'segment' => false); + $urlParams = $this->urlForAction('index', array('segment' => false)); $menu->addPlatformItem(null, $urlParams, 50, $tooltip); $menu->addPlatformItem('General_Widgets', $urlParams, 5, $tooltip); diff --git a/tests/PHPUnit/Core/DeprecatedMethodsTest.php b/tests/PHPUnit/Core/DeprecatedMethodsTest.php index ce496684ba..47bbddb2d2 100644 --- a/tests/PHPUnit/Core/DeprecatedMethodsTest.php +++ b/tests/PHPUnit/Core/DeprecatedMethodsTest.php @@ -29,6 +29,8 @@ class DeprecatedMethodsTest extends PHPUnit_Framework_TestCase $validTill = '2014-10-15'; $this->assertDeprecatedMethodIsRemoved('\Piwik\SettingsPiwik', 'rewriteTmpPathWithHostname', $validTill); + + $this->assertDeprecatedMethodIsRemovedInPiwik3('\Piwik\Menu\MenuAbstract', 'add'); } private function assertDeprecatedMethodIsRemoved($className, $method, $removalDate) @@ -49,4 +51,22 @@ class DeprecatedMethodsTest extends PHPUnit_Framework_TestCase $errorMessage = $className . '::' . $method . ' should be removed as the method is deprecated but it is not.'; $this->assertFalse($methodExists, $errorMessage); } + + private function assertDeprecatedMethodIsRemovedInPiwik3($className, $method) + { + $version = \Piwik\Version::VERSION; + + $class = new ReflectionClass($className); + $methodExists = $class->hasMethod($method); + + if (-1 === version_compare($version, '3.0.0')) { + + $errorMessage = $className . '::' . $method . ' should still exists until 3.0 although it is deprecated.'; + $this->assertTrue($methodExists, $errorMessage); + return; + } + + $errorMessage = $className . '::' . $method . ' should be removed as the method is deprecated but it is not.'; + $this->assertFalse($methodExists, $errorMessage); + } }
\ No newline at end of file |