src/View/DefaultWidgetBuilder.php
public function buildWidget(
        EnvironmentInterface $environment,
        PropertyInterface $property,
        ModelInterface $model
    ) {
        $dispatcher   = $environment->getEventDispatcher();
        $propertyName = $property->getName();
        $propExtra    = $property->getExtra();
        $defName      = $environment->getDataDefinition()->getName();
        $strClass     = $this->getWidgetClass($property);
        if (null === $strClass) {
            return null;
        }

        $event = new DecodePropertyValueForWidgetEvent($environment, $model);
        $event
            ->setProperty($propertyName)
            ->setValue($model->getProperty($propertyName));

        $dispatcher->dispatch($event::NAME, $event);
        $varValue = $event->getValue();

        $propExtra['required']  = ($varValue == '') && !empty($propExtra['mandatory']);
        $propExtra['tableless'] = true;
        if (isset($propExtra['datepicker'])) {
            $propExtra['class'] = $this->addCssClass($propExtra['class'], 'datepicker');
            $propExtra['class'] = $this->addCssClass($propExtra['class'], '-' . $propExtra['rgxp']);
        }
        if (isset($propExtra['colorpicker'])) {
            $propExtra['class'] = $this->addCssClass($propExtra['class'], 'colorpicker');
            if (isset($propExtra['isHexColor'])) {
                $propExtra['class'] = $this->addCssClass($propExtra['class'], '-hex-color');
            }
        }
        if (isset($propExtra['rte'])) {
            $propExtra['class'] = $this->addCssClass($propExtra['class'], 'rte');
            $propExtra['class'] = $this->addCssClass($propExtra['class'], '-' . $propExtra['rte']);
        }

        // Add the (backend) css class for the frontend as well.
        if (isset($propExtra['tl_class'])) {
            $this->addCssClass($propExtra['class'], $propExtra['tl_class']);
        }

        $arrConfig = array(
            'inputType' => $property->getWidgetType(),
            'label'     => array(
                $property->getLabel(),
                $property->getDescription()
            ),
            'options'   => $this->getOptionsForWidget($environment, $property, $model),
            'eval'      => $propExtra,
        );

        if (isset($propExtra['reference'])) {
            $arrConfig['reference'] = $propExtra['reference'];
        }

        $event = new GetAttributesFromDcaEvent(
            $arrConfig,
            $property->getName(),
            $varValue,
            $propertyName,
            $defName,
            new DcCompat($environment, $model, $propertyName)
        );

        $dispatcher->dispatch(ContaoEvents::WIDGET_GET_ATTRIBUTES_FROM_DCA, $event);
        $preparedConfig = $event->getResult();

        // Remove the "Backend.autoSubmit()", add css class for this purpose
        if (isset($preparedConfig['submitOnChange'])) {
            $preparedConfig['class'] = $this->addCssClass($preparedConfig['class'], 'submitOnChange');
            unset($preparedConfig['onclick'], $preparedConfig['onchange']);
        }

        $widget = new $strClass($preparedConfig, new DcCompat($environment, $model, $propertyName));

        $widget->currentRecord = $model->getId();

        $event = new ManipulateWidgetEvent($environment, $model, $property, $widget);
        $dispatcher->dispatch(ManipulateWidgetEvent::NAME, $event);

        return $widget;
    }
public function buildWidget(
        EnvironmentInterface $environment,
        PropertyInterface $property,
        ModelInterface $model
    ) {
        $dispatcher   = $environment->getEventDispatcher();
        $propertyName = $property->getName();
        $propExtra    = $property->getExtra();
        $defName      = $environment->getDataDefinition()->getName();
        $strClass     = $this->getWidgetClass($property);
        if (null === $strClass) {
            return null;
        }

        $event = new DecodePropertyValueForWidgetEvent($environment, $model);
        $event
            ->setProperty($propertyName)
            ->setValue($model->getProperty($propertyName));

        $dispatcher->dispatch($event::NAME, $event);
        $varValue = $event->getValue();

        $propExtra['required']  = ($varValue == '') && !empty($propExtra['mandatory']);
        $propExtra['tableless'] = true;
        if (isset($propExtra['datepicker'])) {
            $propExtra['class'] = $this->addCssClass($propExtra['class'], 'datepicker');
            $propExtra['class'] = $this->addCssClass($propExtra['class'], '-' . $propExtra['rgxp']);
        }
        if (isset($propExtra['colorpicker'])) {
            $propExtra['class'] = $this->addCssClass($propExtra['class'], 'colorpicker');
            if (isset($propExtra['isHexColor'])) {
                $propExtra['class'] = $this->addCssClass($propExtra['class'], '-hex-color');
            }
        }
        if (isset($propExtra['rte'])) {
            $propExtra['class'] = $this->addCssClass($propExtra['class'], 'rte');
            $propExtra['class'] = $this->addCssClass($propExtra['class'], '-' . $propExtra['rte']);
        }

        // Add the (backend) css class for the frontend as well.
        if (isset($propExtra['tl_class'])) {
            $this->addCssClass($propExtra['class'], $propExtra['tl_class']);
        }

        $arrConfig = array(
            'inputType' => $property->getWidgetType(),
            'label'     => array(
                $property->getLabel(),
                $property->getDescription()
            ),
            'options'   => $this->getOptionsForWidget($environment, $property, $model),
            'eval'      => $propExtra,
        );

        if (isset($propExtra['reference'])) {
            $arrConfig['reference'] = $propExtra['reference'];
        }

        $event = new GetAttributesFromDcaEvent(
            $arrConfig,
            $property->getName(),
            $varValue,
            $propertyName,
            $defName,
            new DcCompat($environment, $model, $propertyName)
        );

        $dispatcher->dispatch(ContaoEvents::WIDGET_GET_ATTRIBUTES_FROM_DCA, $event);
        $preparedConfig = $event->getResult();

        // Remove the "Backend.autoSubmit()", add css class for this purpose
        if (isset($preparedConfig['submitOnChange'])) {
            $preparedConfig['class'] = $this->addCssClass($preparedConfig['class'], 'submitOnChange');
            unset($preparedConfig['onclick'], $preparedConfig['onchange']);
        }

        $widget = new $strClass($preparedConfig, new DcCompat($environment, $model, $propertyName));

        $widget->currentRecord = $model->getId();

        $event = new ManipulateWidgetEvent($environment, $model, $property, $widget);
        $dispatcher->dispatch(ManipulateWidgetEvent::NAME, $event);

        return $widget;
    }
Build a widget for a given property.

@param EnvironmentInterface $environment The environment.

@param PropertyInterface    $property    The property.

@param ModelInterface       $model       The current model.

@return \Widget

@SuppressWarnings(PHPMD.CyclomaticComplexity)