category |
---|
Develop |
Piwik contains 4 menus:
-
the top menu (top-right of the page)
-
the user menu (which is accessible when clicking on the username in the top menu)
-
the reporting menu (which includes all the reports like "Actions" and "Visitors")
-
the admin menu (shown in the admin panel)
Plugins can add items to these menus by implementing a Menu
class.
To add a menu class to your plugin, use the console:
$ ./console generate:menu
It will create a plugins/MyPlugin/Menu.php
file:
class Menu extends \Piwik\Plugin\Menu
{
public function configureTopMenu(MenuTop $menu)
{
// ...
}
public function configureUserMenu(MenuUser $menu)
{
// ...
}
public function configureReportingMenu(MenuReporting $menu)
{
// ...
}
public function configureAdminMenu(MenuAdmin $menu)
{
// ...
}
}
Note: URLs can be built using the controller methods:
$this->urlForDefaultAction()
returns the default action (index) for the controller of this plugin$this->urlForAction('foo')
returns the URL for the actionfoo
for the controller of this plugin
public function configureTopMenu(MenuTop $menu)
{
$menu->addItem('My top item', null, $this->urlForDefaultAction());
}
public function configureUserMenu(MenuUser $menu)
{
// add items to an existing category
$menu->addManageItem('My item', $this->urlForDefaultAction());
$menu->addPlatformItem('My item', $this->urlForDefaultAction());
// or create a custom category
$menu->addItem('My category', 'My item', $this->urlForDefaultAction());
}
public function configureReportingMenu(MenuReporting $menu)
{
// add items to an existing category
$menu->addVisitorsItem('Coffee report', $this->urlForAction('showReport'));
$menu->addActionsItem('Coffee report', $this->urlForAction('showReport'));
// or create a custom category named 'Coffee'
$menu->addItem('Coffee', '', $this->urlForDefaultAction());
$menu->addItem('Coffee', 'Coffee report', $this->urlForAction('showReport'));
}
public function configureAdminMenu(MenuAdmin $menu)
{
// add items to an existing category
$menu->addSettingsItem('My admin item', $this->urlForDefaultAction());
$menu->addPlatformItem('My admin item', $this->urlForDefaultAction());
// or create a custom category
$menu->addItem('MyPlugin admin settings', 'My admin item', $this->urlForDefaultAction());
}