diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-06-30 04:18:34 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-06-30 04:18:34 +0400 |
commit | c70371aa61d7b25cfb6f604f765965564e23e292 (patch) | |
tree | 2d73e79dedfb1be97e41aafb04f810c0b0569455 /core/WidgetsList.php | |
parent | a630dead90724060c23f9ac8ddec97cb06fcd8b5 (diff) |
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
Diffstat (limited to 'core/WidgetsList.php')
-rw-r--r-- | core/WidgetsList.php | 32 |
1 files changed, 22 insertions, 10 deletions
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 |