Piwik\Widget\

WidgetsList

Manages the global list of reports that can be displayed as dashboard widgets.

Widgets are added through the WidgetsList.addWidgets and filtered through the Widgets.filterWidgets event. Observers for this event should call the addWidget() method to add widgets or use any of the other methods to remove widgets.

Methods

The class defines the following methods:

  • addWidgetConfig() — Adds a new widget to the widget config.
  • addWidgetConfigs() — Add multiple widget configs at once.
  • getWidgetConfigs() — Get all added widget configs.
  • addToContainerWidget() — Add a widget to a widget container.
  • remove() — Removes one or more widgets from the widget list.
  • isDefined() — Returns true if a widget exists in the widget list, false if otherwise.
  • getWidgetUniqueId() — CAUTION! If you ever change this method, existing updates will fail as they currently use that method! If you change the output the uniqueId for existing widgets would not be found anymore

addWidgetConfig()

Adds a new widget to the widget config. Please make sure the widget is enabled before adding a widget as no such checks will be performed.

Signature

  • It accepts the following parameter(s):

  • It does not return anything or a mixed result.

addWidgetConfigs()

Add multiple widget configs at once. See addWidgetConfig().

Signature

  • It accepts the following parameter(s):

  • It does not return anything or a mixed result.

getWidgetConfigs()

Get all added widget configs.

Signature

addToContainerWidget()

Add a widget to a widget container. It doesn't matter whether the container was added to this list already or whether the container is added later. As long as a container having the same containerId is added at some point the widget will be added to that container. If no container having this id is added the widget will not be recognized.

Signature

  • It accepts the following parameter(s):

    • $containerId (string) — eg 'Products' or 'Contents'. See WidgetContainerConfig::setId
    • $widget (WidgetConfig) —
  • It does not return anything or a mixed result.

remove()

Removes one or more widgets from the widget list.

Signature

  • It accepts the following parameter(s):
    • $widgetCategoryId (string) — The widget category id. Can be a translation token eg 'General_Visits' see WidgetConfig::setCategoryId().
    • $widgetName (string|false) — The name of the widget to remove eg 'VisitTime_ByServerTimeWidgetName'. If not supplied, all widgets within that category will be removed.
  • It does not return anything or a mixed result.

isDefined()

Returns true if a widget exists in the widget list, false if otherwise.

Signature

  • It accepts the following parameter(s):
    • $module (string) — The controller name of the widget.
    • $action (string) — The controller action of the widget.
  • It returns a bool value.

getWidgetUniqueId()

CAUTION! If you ever change this method, existing updates will fail as they currently use that method! If you change the output the uniqueId for existing widgets would not be found anymore

Returns the unique id of an widget with the given parameters

Signature

  • It accepts the following parameter(s):

    • $controllerName

    • $controllerAction

    • $customParameters (array) —

  • It returns a string value.