@param array  $widgetConfiguration
@param Widget $widget

@return Widget
763958
private function persistWidget($widgetConfiguration, Widget $widget)
    {
        $widget->setName($widgetConfiguration['name']);
        $widget->setContext(isset($widgetConfiguration['context']) ? $widgetConfiguration['context'] : []);
        $widget->setSources(isset($widgetConfiguration['sources']) ? $widgetConfiguration['sources'] : []);
        $widget->setClass(isset($widgetConfiguration['class']) ? $widgetConfiguration['class'] : null);
        $widget->setExportable($widgetConfiguration['exportable']);
        $widget->setTags(isset($widgetConfiguration['tags']) ? $widgetConfiguration['tags'] : []);

        $this->em->persist($widget);

        return $widget;
    }
1028717
public function overwriteWidget(View $view, Widget $widget)
    {
        $widgetCopy = $this->cloneEntity($widget);
        $originalWidgetMap = $widget->getWidgetMap();
        $this->widgetMapManager->overwrite($view, $originalWidgetMap, $widgetCopy);

        return $widgetCopy;
    }
378897
public function endWidget($widget = null)
    {
        if ($widget === null) {
            if (empty($this->widgets)) {
                throw new TemplateException('Unexpected end_widget() call. A matching begin_widget() is not found.');
            }
            $this->call(array_pop($this->widgets), 'end');
        } else {
            array_pop($this->widgets);
            $this->resolveAndCall($widget, 'end');
        }
    }
523101
public function getWidgetStaticContent(Widget $widget)
    {
        $reflect = new \ReflectionClass($widget);
        $widgetProperties = $reflect->getProperties();
        $parameters = ['widget' => $widget];
        $accessor = PropertyAccess::createPropertyAccessor();

        foreach ($widgetProperties as $property) {
            if (!$property->isStatic()) {
                $value = $accessor->getValue($widget, $property->getName());
                $parameters[$property->getName()] = $value;
            }
        }

        return $parameters;
    }
454150
public function widget($className, $attributes = array())
    {
        static $widgets = array();

        // If the class name is not lead with upper case add prefix "Widget".
        if (! preg_match('|^[A-Z]|', $className)) {
            $className = ucfirst($className);
        }

        $widgetNamespace = $this->getConfig('namespaces.widget');

        $className = $widgetNamespace.'\\'.$className;

        if (! $instance = array_get($widgets, $className)) {
            $reflector = new ReflectionClass($className);

            if (! $reflector->isInstantiable()) {
                throw new UnknownWidgetClassException("Widget target [$className] is not instantiable.");
            }

            $instance = $reflector->newInstance($this, $this->config, $this->view);
            array_set($widgets, $className, $instance);
        }

        $instance->setAttributes($attributes);
        $instance->beginWidget();
        $instance->endWidget();

        return $instance;
    }
181021
public function getNewDataWidget($widgetType, User $user)
    {
        $widget = $this->widgetFactory->createDataWidget($widgetType);
        $widget
            ->setId(uniqid())
            ->setUser($user);

        return $widget;
    }
1289226
public function addWidget(WidgetInterface $widget)
    {
        if ($this->hasWidget($widget)) {
            throw new \InvalidArgumentException(sprintf('Widget "%s" is already registered.', $widget->getName()));
        }

        $this->widgets[$widget->getName()] = $widget;

        return $this;
    }
1275277
public function beginWidget($widget, $config = [])
    {
        $widget = $this->resolveClassName($widget);
        $this->widgets[] = $widget;
        return $this->call($widget, 'begin', [
            $config,
        ]);
    }
54894
public function onCopyWidgetConfiguration(CopyWidgetConfigurationEvent $event)
    {
        $source = $event->getWidgetInstance();
        $copy = $event->getWidgetInstanceCopy();

        $widgetConfig = $this->logManager->getLogConfig($source);

        if (!is_null($widgetConfig)) {
            $widgetConfigCopy = new LogWidgetConfig();
            $widgetConfigCopy->setWidgetInstance($copy);
            $widgetConfigCopy->setAmount($widgetConfig->getAmount());
            $widgetConfigCopy->setRestrictions($widgetConfig->getRestrictions());

            $this->om->persist($widgetConfigCopy);
            $this->om->flush();
        }
        $event->validateCopy();
        $event->stopPropagation();
    }
1048287
public function setWidget(SwatWidget $widget)
    {
        if ($this->widget !== null) {
            throw new SwatException(
                'SwatUI: Only one widget can be nested ' .
                    'within a SwatActionItem'
            );
        }

        $this->widget = $widget;
        $widget->parent = $this;
    }
1273617
private function getModelFromWidget(Widget $widget)
    {
        if ($widget->dataContainer) {
            return $widget->dataContainer->getModel();
        }

        return $widget->getModel();
    }
617954
public function addWidgets( $widget, $services )
    {
        foreach ( $services as $key => $description )
        {
            if ( null === $description || is_scalar( $description ) )
            {
                $service    = $key;
                $priority   = null === $description ? null : (int) $description;
            }
            else
            {
                if ( $description instanceof \Traversable )
                {
                    $description = iterator_to_array( $description );
                }
                else if ( ! $description instanceof \ArrayAccess )
                {
                    $description = (array) $description;
                }

                if ( ! isset( $description['service'] ) )
                {
                    continue;
                }

                $service = $description['service'];

                if ( isset( $description['priority'] ) )
                {
                    $priority = (int) $description['priority'];
                }
                else
                {
                    $priority = null;
                }
            }

            $this->addWidget( $widget, $service, $priority );
        }

        return $this;
    }
985464
public static function factory( ServiceLocatorInterface $serviceLocator, $widgets = array() )
    {
        $viewWidget = new static( $serviceLocator );

        foreach ( $widgets as $widget => $services )
        {
            $viewWidget->addWidgets( $widget, $services );
        }

        return $viewWidget;
    }
1314288
public function getWidgetMapByWidgetId($widgetId)
    {
        $widgetMap = null;

        $widgetMaps = $this->widgetMaps;

        //parse the widgets maps
        foreach ($widgetMaps as $wm) {
            if ($wm->getWidgetId() === $widgetId) {
                $widgetMap = $wm;
                //entity found, there is no need to continue
                break;
            }
        }

        return $widgetMap;
    }
1141987
public function loadRichTextEditor($buffer, Widget $widget)
    {
        if ((null === $widget->rte)
            || ((0 !== (\strncmp($widget->rte, 'tiny', 4)))
                && (0 !== \strncmp($widget->rte, 'ace', 3)))
        ) {
            return $buffer;
        }

        $backendAdapter        = $this->framework->getAdapter(Backend::class);
        $templateLoaderAdapter = $this->framework->getAdapter(TemplateLoader::class);

        [$file, $type] = \explode('|', $widget->rte);

        $templateName = 'be_' . $file;
        // This test if the rich text editor template exist.
        $templateLoaderAdapter->getDefaultPath($templateName, 'html5');

        $template = new ContaoBackendViewTemplate($templateName);
        $template
            ->set('selector', 'ctrl_' . $widget->id)
            ->set('type', $type);

        if (0 !== \strncmp($widget->rte, 'tiny', 4)) {
            /** @deprecated Deprecated since Contao 4.0, to be removed in Contao 5.0 */
            $template->set('language', $backendAdapter->getTinyMceLanguage());
        }

        $buffer .= $template->parse();

        return $buffer;
    }
119148
public function getWidgetName(Widget $widget)
    {
        $widgets = $this->container->getParameter('victoire_core.widgets');
        foreach ($widgets as $widgetParams) {
            if ($widgetParams['class'] === ClassUtils::getClass($widget)) {
                return $widgetParams['name'];
            }
        }

        throw new \Exception('Widget name not found for widget '.get_class($widget).'. Is this widget right declared in AppKernel ?');
    }
452323
public function getInputGroup(Widget $widget)
    {
        if ($this->widgetConfig[$widget->type]['input_group'] && $widget->bs_addInputGroup) {
            return InputGroupHelper::forWidget($widget);
        }

        return null;
    }