Retrieve the dashboard's widgets.

@param callable $widgetCallback A callback applied to each widget.
@return UiItemInterface[]|\Generator
4669
public function widgets(callable $widgetCallback = null)
    {
        $widgets = $this->widgets;

        $gridStack = $this->gridStack() ?: [];
        $parsedGridStack = [];

        array_walk($gridStack, function ($item) use (&$parsedGridStack) {
            $parsedGridStack[$item['id']] = $item;
        });

        // Load gridStack from user preferences
        $user = $this->adminUser();
        $userGridStack = json_decode($user->preferences(), true)['grid_stack'] ?: [];
        $parsedUserGridStack = [];

        array_walk($userGridStack, function ($item) use (&$parsedUserGridStack) {
            $parsedUserGridStack[$item['id']] = $item;
        });

        $widgetCallback = isset($widgetCallback) ? $widgetCallback : $this->widgetCallback;
        foreach ($widgets as $widget) {
            if (isset($widget['permissions']) && $this instanceof AuthAwareInterface) {
                $widget->setActive($this->hasPermissions($widget['permissions']));
            }

            if (!!count($parsedUserGridStack)) {
                if (isset($parsedUserGridStack[$widget->ident()])) {
                    $widget->setData([
                        'grid_stack' => $parsedUserGridStack[$widget->ident()]
                    ]);
                }
            } else {
                if (isset($parsedGridStack[$widget->ident()])) {
                    $gridStack  = array_replace_recursive(
                        $parsedGridStack[$widget->ident()],
                        $widget['grid_stack'] ?: []
                    );

                    $widget->setData([
                        'grid_stack' => $gridStack
                    ]);
                }
            }

            $gridStackDeco = new GridStackWidgetDecorator($widget);
            $widget['grid_stack'] = $gridStackDeco->gridStack();

            if (!$widget->active()) {
                continue;
            }

            if ($widgetCallback) {
                $widgetCallback($widget);
            }

            $GLOBALS['widget_template'] = $widget->template();

            yield $widget;

            $GLOBALS['widget_template'] = '';
        }
    }
707738
def get_widgets(self):
        
        widgets = OrderedDict()
        mappings = {}
        for dim in self.mock_obj.kdims:
            holomap = None if self.plot.dynamic else self.mock_obj
            widget, label, mapping = self.create_widget(dim, holomap, self.editable)
            if label is not None and not isinstance(label, Div):
                label.on_change('value', partial(self.on_change, dim, 'label'))
            widget.on_change('value', partial(self.on_change, dim, 'widget'))
            widgets[dim.pprint_label] = (label, widget)
            if mapping:
                mappings[dim.pprint_label] = OrderedDict(mapping)
        return widgets, mappings
856118
public function inputs(callable $inputCallback = null)
    {
        $groups = $this->groups;
        uasort($groups, [ $this, 'sortItemsByPriority' ]);

        $inputCallback = isset($inputCallback) ? $inputCallback : $this->inputCallback;
        foreach ($inputs as $input) {
            if (!$input->l10nMode()) {
                $input->setL10nMode($this->l10nMode());
            }
            if ($inputCallback) {
                $inputCallback($input);
            }
            $GLOBALS['widget_template'] = $input->template();
            yield $input->ident() => $input;
            $GLOBALS['widget_template'] = '';
        }
    }
11591
public function getContextualSubstitutes()
    {
        $substitutesWidgetMaps = [];
        $viewWidgetMaps = $this->getContextualView()->getWidgetMapsForViewAndTemplates();

        foreach ($viewWidgetMaps as $viewWidgetMap) {
            if ($viewWidgetMap->getReplaced() == $this) {
                $substitutesWidgetMaps[] = $viewWidgetMap;
            }
        }

        return $substitutesWidgetMaps;
    }
32359
protected function getAll()
    {
        $widgets = getConfig('Widgets.general', []);

        if ($this->getView()->getRequest()->isUrl(['_name' => 'homepage']) && getConfig('Widgets.homepage')) {
            $widgets = getConfig('Widgets.homepage');
        }

        return $widgets ? collection($widgets)->map(function ($args, $name) {
            if (is_string($name) && is_array($args)) {
                return [$name => $args];
            } elseif (is_string($args)) {
                return [$args => []];
            }

            list($name, $args) = [array_key_first($args), array_value_first($args)];

            return is_int($name) && is_string($args) ? [$args => []] : [$name => $args];
        })->toList() : [];
    }
789070
private function getMappings($entityClass)
    {
        if ($this->metadataManager->hasMetadata($entityClass)) {
            return $this->metadataManager->getMetadata($entityClass)->getMappings();
        }
        try {
            return $this->em->getClassMetadata($entityClass)->fieldMappings;
        } catch (MappingException $ex) {
            throw new WidgetException(sprintf('Unable to get Doctrine metadata for class "%s".', $entityClass));
        }
    }
297494
private function getArguments(callable $callback, array $callbackArguments)
    {
        $parameters = $this->getParameters($callback);
        $arguments = [];
        foreach ($parameters as $param) {
            if (array_key_exists($param->getName(), $callbackArguments)) {
                $arguments[] = $callbackArguments[$param->getName()];
            } elseif ($param->isDefaultValueAvailable()) {
                $arguments[] = $param->getDefaultValue();
            } else {
                $arguments[$param->getName()] = null;
            }
        }

        return $arguments;
    }
425799
public static function get_widget_instance( $widget_id ) {
		global $wp_registered_widgets;

		if ( ! isset( $wp_registered_widgets[ $widget_id ] ) ) {
			return false;
		}

		$model = $wp_registered_widgets[ $widget_id ]['callback'][0];

		if ( ! is_a( $model, 'Lean\Widgets\Models\AbstractWidget' ) ) {
			return false;
		}

		$key = $wp_registered_widgets[ $widget_id ]['params'][0]['number'];

		$model->_set( $key );

		return $model;
	}
149065
protected function reorderWidgets($widgets)
    {
        $formatted = [];

        foreach ($widgets as $key => $widget) {
            if (is_array($widget)) {
                $formatted[] = [
                    'name' => array_get($widget, 0),
                    'order' => array_get($widget, 1),
                ];
            } else {
                $formatted[] = [
                    'name' => $widget,
                    'order' => $key,
                ];
            }
        }

        return collect($formatted)->sortBy(function ($widget) {
            return $widget['order'];
        })->all();
    }
1273617
private function getModelFromWidget(Widget $widget)
    {
        if ($widget->dataContainer) {
            return $widget->dataContainer->getModel();
        }

        return $widget->getModel();
    }
1300606
protected function callStringCallback($callback, $args = [])
    {
        if (strpos($callback, '@')) {
            list($klass, $method) = explode('@', $callback);
        } else {
            $klass  = $callback;
            $method = 'render';
        }

        $klass = isset($this->instantiatedWidgets[$klass]) ? $this->instantiatedWidgets[$klass] : new $klass;

        return call_user_func_array([$klass, $method], $args);
    }
1283139
public static function get()
    {
        $list = new static;

        $widgets = StaticContainer::get('Piwik\Plugin\WidgetsProvider');

        $widgetContainerConfigs = $widgets->getWidgetContainerConfigs();
        foreach ($widgetContainerConfigs as $config) {
            if ($config->isEnabled()) {
                $list->addWidgetConfig($config);
            }
        }

        $widgetConfigs = $widgets->getWidgetConfigs();
        foreach ($widgetConfigs as $widget) {
            if ($widget->isEnabled()) {
                $list->addWidgetConfig($widget);
            }
        }

        $reports = StaticContainer::get('Piwik\Plugin\ReportsProvider');
        $reports = $reports->getAllReports();
        foreach ($reports as $report) {
            if ($report->isEnabled()) {
                $factory = new ReportWidgetFactory($report);
                $report->configureWidgets($list, $factory);
            }
        }

        /**
         * Triggered to filter widgets.
         *
         * **Example**
         *
         *     public function removeWidgetConfigs(Piwik\Widget\WidgetsList $list)
         *     {
         *         $list->remove($category='General_Visits'); // remove all widgets having this category
         *     }
         *
         * @param WidgetsList $list An instance of the WidgetsList. You can change the list of widgets this way.
         */
        Piwik::postEvent('Widget.filterWidgets', array($list));

        return $list;
    }
238110
public static function widgets()
    {
        //====================================================================//
        // Check if Widget Manager is Overriden
        if (self::local() instanceof WidgetsProviderInterface) {
            return self::local()->widgets();
        }
        $widgetTypes = array();
        //====================================================================//
        // Safety Check => Verify Objects Folder Exists
        $path = self::getLocalPath().'/Widgets';
        if (!is_dir($path)) {
            return $widgetTypes;
        }
        //====================================================================//
        // Scan Local Objects Folder
        $scan = scandir($path, 1);
        if (false == $scan) {
            return $widgetTypes;
        }
        //====================================================================//
        // Scan Each File in Folder
        $files = array_diff($scan, array('..', '.', 'index.php', 'index.html'));
        foreach ($files as $filename) {
            $className = pathinfo($path.'/'.$filename, PATHINFO_FILENAME);
            //====================================================================//
            // Verify ClassName is a Valid Object File
            if (false == self::validate()->isValidWidget($className)) {
                continue;
            }
            $widgetTypes[] = $className;
        }

        return $widgetTypes;
    }
997537
private function getWidgetContent(WidgetInterface $widget)
    {
        if (!isset($this->widgetContents[$widget->getName()])) {
            try {
                $this->widgetContents[$widget->getName()] = $widget->getContent();
            } catch (KernelHttpException $ex) {
                throw new HttpException($ex);
            }
        }

        return $this->widgetContents[$widget->getName()];
    }
728128
protected function handleClassCallback(string $callback): array
    {
        list($class, $method) = $this->parseCallback($callback);
        $instance = $this->container->make($class);

        return [$instance, $method];
    }
645619
public function getWidgets()
    {
        $widgets = parent::getWidgets();

        $upperThreshold = DebugBar::config()->get('warn_request_time_seconds');
        $warningRatio = DebugBar::config()->get('warn_warning_ratio');

        // Can be disabled by setting the value to false
        if (!is_numeric($upperThreshold)) {
            return $widgets;
        }

        $widgets['time']['indicator'] = 'PhpDebugBar.DebugBar.WarnableRequestTimeIndicator';
        $widgets['time']['warn'] = 'ok';
        // Request duration rather than Request Duration
        $widgets['time']['tooltip'] = ucfirst(strtolower($widgets['time']['tooltip']));

        $warningThreshold = $upperThreshold * $warningRatio;
        if ($this->getRequestDuration() > $upperThreshold) {
            $widgets['time']['warn'] = 'danger';
            $widgets['time']['tooltip'] .= ' > ' . $upperThreshold . ' seconds';
        } elseif ($this->getRequestDuration() > $warningThreshold) {
            $widgets['time']['warn'] = 'warning';
            $widgets['time']['tooltip'] .= ' > ' . $warningThreshold . ' seconds';
        } else {
            $widgets['time']['tooltip'] .= ' < ' . $warningThreshold . ' seconds';
        }

        return $widgets;
    }
945174
public static function forWidget(Widget $widget): self
    {
        $values = StringUtil::deserialize($widget->bs_inputGroup, true);
        $helper = new static();

        foreach ($values as $entry) {
            if (!strlen($entry['addon'])) {
                continue;
            }

            if ($entry['position'] === 'after') {
                $helper->addAfter($entry['addon']);
            } else {
                $helper->addBefore($entry['addon']);
            }
        }

        return $helper;
    }