Click here if you want to read this article for the latest Piwik version

Piwik\Plugin\

Menu

Since Piwik 2.4.0

Base class of all plugin menu providers.

Plugins that define their own menu items can extend this class to easily add new items, to remove or to rename existing items.

Descendants of this class can overwrite any of these methods. Each method will be executed only once per request and cached for any further menu requests.

For an example, see the https://github.com/piwik/piwik/blob/master/plugins/ExampleUI/Menu.php plugin.

Methods

The class defines the following methods:

  • __construct()
  • urlForDefaultAction() — Generates a URL for the default action of the plugin controller.
  • urlForAction() — Generates a URL for the given action.
  • urlForDefaultUserParams() — Returns the &idSite=X&period=Y&date=Z query string fragment, fetched from current logged-in user's preferences.
  • configureReportingMenu() ash; Configures the reporting menu which should only contain links to reports of a specific site such as "Search Engines", "Page Titles" or "Locations & Provider".
  • configureTopMenu() ash; Configures the top menu which is supposed to contain analytics related items such as the "All Websites Dashboard".
  • configureUserMenu() ash; Configures the user menu which is supposed to contain user and help related items such as "User settings", "Alerts" or "Email Reports".
  • configureAdminMenu() ash; Configures the admin menu which is supposed to contain only administration related items such as "Websites", "Users" or "Plugin settings".

__construct()

Signature

urlForDefaultAction()

Since Piwik 2.7.0

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

Signature

  • It accepts the following parameter(s):
    • $additionalParams (array) — Optional URL parameters that will be appended to the URL
  • It returns a array value.

urlForAction()

Since Piwik 2.7.0

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 urlForModuleAction().

Signature

  • It accepts the following parameter(s):
    • $controllerAction (string) — The name of the action that should be executed within your controller
    • $additionalParams (array) — Optional URL parameters that will be appended to the URL
  • It returns a array value.

urlForDefaultUserParams()

Returns the &idSite=X&period=Y&date=Z query string fragment, fetched from current logged-in user's preferences.

Signature

  • It accepts the following parameter(s):

    • $websiteId (bool) —

    • $defaultPeriod (bool) —

    • $defaultDate (bool) —

  • Returns: string — eg '&idSite=1&period=week&date=today'

  • It throws one of the following exceptions:
    • Exception — in case a website was not specified and a default website id could not be found

configureReportingMenu()

Configures the reporting menu which should only contain links to reports of a specific site such as "Search Engines", "Page Titles" or "Locations & Provider".

Signature

  • It accepts the following parameter(s):

  • It does not return anything.

configureTopMenu()

Configures the top menu which is supposed to contain analytics related items such as the "All Websites Dashboard".

Signature

  • It accepts the following parameter(s):

  • It does not return anything.

configureUserMenu()

Configures the user menu which is supposed to contain user and help related items such as "User settings", "Alerts" or "Email Reports".

Signature

  • It accepts the following parameter(s):

  • It does not return anything.

configureAdminMenu()

Configures the admin menu which is supposed to contain only administration related items such as "Websites", "Users" or "Plugin settings".

Signature

  • It accepts the following parameter(s):

  • It does not return anything.