src/View/WidgetManager.php
public function getWidget($property, PropertyValueBag $valueBag = null)
    {
        $environment         = $this->getEnvironment();
        $dispatcher          = $environment->getEventDispatcher();
        $propertyDefinitions = $environment->getDataDefinition()->getPropertiesDefinition();

        if (!$propertyDefinitions->hasProperty($property)) {
            throw new DcGeneralInvalidArgumentException(
                'Property ' . $property . ' is not defined in propertyDefinitions.'
            );
        }

        $model = clone $this->model;
        $model->setId($this->model->getId());

        if ($valueBag) {
            $values = new PropertyValueBag($valueBag->getArrayCopy());
            $this->environment->getController()->updateModelFromPropertyBag($model, $values);
        }

        $propertyDefinition = $propertyDefinitions->getProperty($property);
        $event              = new BuildWidgetEvent($environment, $model, $propertyDefinition);

        $dispatcher->dispatch(DcGeneralFrontendEvents::BUILD_WIDGET, $event);
        if (!$event->getWidget()) {
            throw new DcGeneralRuntimeException(
                sprintf('Widget was not build for property %s::%s.', $this->model->getProviderName(), $property)
            );
        }

        return $event->getWidget();
    }
public function getWidget($property, PropertyValueBag $valueBag = null)
    {
        $environment         = $this->getEnvironment();
        $dispatcher          = $environment->getEventDispatcher();
        $propertyDefinitions = $environment->getDataDefinition()->getPropertiesDefinition();

        if (!$propertyDefinitions->hasProperty($property)) {
            throw new DcGeneralInvalidArgumentException(
                'Property ' . $property . ' is not defined in propertyDefinitions.'
            );
        }

        $model = clone $this->model;
        $model->setId($this->model->getId());

        if ($valueBag) {
            $values = new PropertyValueBag($valueBag->getArrayCopy());
            $this->environment->getController()->updateModelFromPropertyBag($model, $values);
        }

        $propertyDefinition = $propertyDefinitions->getProperty($property);
        $event              = new BuildWidgetEvent($environment, $model, $propertyDefinition);

        $dispatcher->dispatch(DcGeneralFrontendEvents::BUILD_WIDGET, $event);
        if (!$event->getWidget()) {
            throw new DcGeneralRuntimeException(
                sprintf('Widget was not build for property %s::%s.', $this->model->getProviderName(), $property)
            );
        }

        return $event->getWidget();
    }
Retrieve the instance of a widget for the given property.

@param string           $property Name of the property for which the widget shall be retrieved.

@param PropertyValueBag $valueBag The input values to use (optional).

@return \Widget

@throws DcGeneralRuntimeException         When No widget could be build.
@throws DcGeneralInvalidArgumentException When property is not defined in the property definitions.