From bedfa1c9de069801d58de9642c92f8681c69d7bb Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Fri, 6 Jun 2014 05:50:06 +0200 Subject: working on simplifying widgets. Pushing into a branch since I am not 100% happy with it yet. --- core/WidgetsList.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'core/WidgetsList.php') diff --git a/core/WidgetsList.php b/core/WidgetsList.php index bb85a37349..75c75937d8 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,8 +17,9 @@ 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 @@ -71,20 +74,17 @@ 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'); + + foreach ($widgets as $widget) { + $widget->configure(WidgetsList::getInstance()); + } } } -- cgit v1.2.3 From e6607932067a0614f40c31d05990f8f5e9e358f5 Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Mon, 9 Jun 2014 23:03:15 +0200 Subject: fix tests --- core/WidgetsList.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'core/WidgetsList.php') diff --git a/core/WidgetsList.php b/core/WidgetsList.php index 75c75937d8..095c54cfd7 100644 --- a/core/WidgetsList.php +++ b/core/WidgetsList.php @@ -26,7 +26,7 @@ class WidgetsList extends Singleton * * @var array */ - static protected $widgets = null; + static protected $widgets = array(); /** * Indicates whether the hook was posted or not @@ -80,10 +80,11 @@ class WidgetsList extends Singleton Piwik::postEvent('WidgetsList.addWidgets'); /** @var \Piwik\Plugin\Widgets[] $widgets */ - $widgets = PluginManager::getInstance()->findComponents('Widgets', 'Piwik\\Plugin\\Widgets'); + $widgets = PluginManager::getInstance()->findComponents('Widgets', 'Piwik\\Plugin\\Widgets'); + $widgetsList = self::getInstance(); foreach ($widgets as $widget) { - $widget->configure(WidgetsList::getInstance()); + $widget->configure($widgetsList); } } } @@ -145,6 +146,11 @@ class WidgetsList extends Singleton } $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 extends Singleton */ public static function _reset() { - self::$widgets = null; + self::$widgets = array(); self::$hookCalled = false; } } -- cgit v1.2.3