From c70371aa61d7b25cfb6f604f765965564e23e292 Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Mon, 30 Jun 2014 02:18:34 +0200 Subject: refs #5326 as mentioned in the ticket once we have simplified the reports we can simplify the widgets api even more which is done in this commit, it might be not perfect yet but again much better than before --- core/WidgetsList.php | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'core/WidgetsList.php') diff --git a/core/WidgetsList.php b/core/WidgetsList.php index 420f5f76b6..531d802405 100644 --- a/core/WidgetsList.php +++ b/core/WidgetsList.php @@ -8,8 +8,8 @@ */ namespace Piwik; -use Piwik\Plugin\Manager as PluginManager; use Piwik\Plugin\Report; +use Piwik\Plugin\Widgets; /** * Manages the global list of reports that can be displayed as dashboard widgets. @@ -61,11 +61,15 @@ class WidgetsList extends Singleton $widgets = array(); foreach (self::$widgets as $key => $v) { - if (isset($widgets[Piwik::translate($key)])) { - $v = array_merge($widgets[Piwik::translate($key)], $v); + $category = Piwik::translate($key); + + if (isset($widgets[$category])) { + $v = array_merge($widgets[$category], $v); } - $widgets[Piwik::translate($key)] = $v; + + $widgets[$category] = $v; } + return $widgets; } @@ -80,8 +84,6 @@ class WidgetsList extends Singleton */ Piwik::postEvent('WidgetsList.addWidgets'); - /** @var \Piwik\Plugin\Widgets[] $widgets */ - $widgets = PluginManager::getInstance()->findComponents('Widgets', 'Piwik\\Plugin\\Widgets'); $widgetsList = self::getInstance(); foreach (Report::getAllReports() as $report) { @@ -90,8 +92,17 @@ class WidgetsList extends Singleton } } - foreach ($widgets as $widget) { - $widget->configure($widgetsList); + $widgetContainers = Widgets::getAllWidgets(); + foreach ($widgetContainers as $widgetContainer) { + $widgets = $widgetContainer->getWidgets(); + + foreach ($widgets as $widget) { + $widgetsList->add($widget['category'], $widget['name'], $widget['module'], $widget['method'], $widget['params']); + } + } + + foreach ($widgetContainers as $widgetContainer) { + $widgetContainer->configureWidgetsList($widgetsList); } } } @@ -143,8 +154,9 @@ class WidgetsList extends Singleton */ static public function add($widgetCategory, $widgetName, $controllerName, $controllerAction, $customParameters = array()) { - $widgetName = Piwik::translate($widgetName); + $widgetName = Piwik::translate($widgetName); $widgetUniqueId = 'widget' . $controllerName . $controllerAction; + foreach ($customParameters as $name => $value) { if (is_array($value)) { // use 'Array' for backward compatibility; @@ -203,7 +215,7 @@ class WidgetsList extends Singleton static public function isDefined($controllerName, $controllerAction) { $widgetsList = self::get(); - foreach ($widgetsList as $widgetCategory => $widgets) { + foreach ($widgetsList as $widgets) { foreach ($widgets as $widget) { if ($widget['parameters']['module'] == $controllerName && $widget['parameters']['action'] == $controllerAction -- cgit v1.2.3