Piwik\Plugin\WidgetsProvider::factory PHP Метод

factory() публичный Метод

Get the widget defined by the given module and action.
public factory ( string $module, string $action ) : Widget | null
$module string Aka plugin name, eg 'CoreHome'
$action string An action eg 'renderMe'
Результат Piwik\Widget\Widget | null
    public function factory($module, $action)
    {
        if (empty($module) || empty($action)) {
            return;
        }
        try {
            if (!$this->pluginManager->isPluginActivated($module)) {
                return;
            }
            $plugin = $this->pluginManager->getLoadedPlugin($module);
        } catch (\Exception $e) {
            // we are not allowed to use possible widgets, plugin is not active
            return;
        }
        /** @var Widget[] $widgetContainer */
        $widgets = $plugin->findMultipleComponents('Widgets', 'Piwik\\Widget\\Widget');
        foreach ($widgets as $widgetClass) {
            $config = $this->getWidgetConfigForClassName($widgetClass);
            if ($config->getAction() === $action) {
                $config->checkIsEnabled();
                return StaticContainer::get($widgetClass);
            }
        }
    }

Usage Example

Пример #1
0
 private function createWidgetController($module, $action, array &$parameters)
 {
     $widget = $this->widgets->factory($module, $action);
     if (!$widget) {
         return;
     }
     $parameters['widget'] = $widget;
     return array($this->createCoreHomeController(), 'renderWidget');
 }