diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2014-06-10 06:39:02 +0400 |
---|---|---|
committer | Thomas Steur <tsteur@users.noreply.github.com> | 2014-06-10 06:39:02 +0400 |
commit | b8aa95f7fe7b251abe81bd6664c2a15cf5129197 (patch) | |
tree | 073d50b6a46c09e491181df01150115f091bc28e /core/WidgetsList.php | |
parent | 3a28d26de32257045850ea5a602b970a9b5be3f7 (diff) | |
parent | 0dc6a6cb8d12d95f172b754405929e5db439d551 (diff) |
Merge pull request #308 from piwik/plugin_widget_refactoring
refs #5326 Provide simpler Widgets API
Diffstat (limited to 'core/WidgetsList.php')
-rw-r--r-- | core/WidgetsList.php | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/core/WidgetsList.php b/core/WidgetsList.php index 3cc10f24b9..b79b94d922 100644 --- a/core/WidgetsList.php +++ b/core/WidgetsList.php @@ -8,6 +8,8 @@ */ namespace Piwik; +use Piwik\Plugin\Manager as PluginManager; + /** * Manages the global list of reports that can be displayed as dashboard widgets. * @@ -15,15 +17,16 @@ namespace Piwik; * event. Observers for this event should call the {@link add()} method to add reports. * * @api + * @method static \Piwik\WidgetsList getInstance() */ -class WidgetsList +class WidgetsList extends Singleton { /** * List of widgets * * @var array */ - static protected $widgets = null; + static protected $widgets = array(); /** * Indicates whether the hook was posted or not @@ -71,20 +74,18 @@ class WidgetsList self::$hookCalled = true; /** - * Used to collect all available dashboard widgets. - * - * Subscribe to this event to make your plugin's reports or other controller actions available - * as dashboard widgets. Event handlers should call the {@link WidgetsList::add()} method for each - * new dashboard widget. - * - * **Example** - * - * public function addWidgets() - * { - * WidgetsList::add('General_Actions', 'General_Pages', 'Actions', 'getPageUrls'); - * } + * @ignore + * @deprecated */ Piwik::postEvent('WidgetsList.addWidgets'); + + /** @var \Piwik\Plugin\Widgets[] $widgets */ + $widgets = PluginManager::getInstance()->findComponents('Widgets', 'Piwik\\Plugin\\Widgets'); + $widgetsList = self::getInstance(); + + foreach ($widgets as $widget) { + $widget->configure($widgetsList); + } } } @@ -145,6 +146,11 @@ class WidgetsList } $widgetUniqueId .= $name . $value; } + + if (!array_key_exists($widgetCategory, self::$widgets)) { + self::$widgets[$widgetCategory] = array(); + } + self::$widgets[$widgetCategory][] = array( 'name' => $widgetName, 'uniqueId' => $widgetUniqueId, @@ -209,7 +215,7 @@ class WidgetsList */ public static function _reset() { - self::$widgets = null; + self::$widgets = array(); self::$hookCalled = false; } } |