示例#1
0
 /**
  * Get the widget instance.
  *
  * @param string $fieldName     The property name.
  *
  * @param string $serializedId  The serialized id of the model.
  *
  * @param string $propertyValue The property value.
  *
  * @return \Widget
  */
 protected function getWidget($fieldName, $serializedId, $propertyValue)
 {
     $environment = $this->getEnvironment();
     $property = $environment->getDataDefinition()->getPropertiesDefinition()->getProperty($fieldName);
     $propertyValues = new PropertyValueBag();
     if ($serializedId !== null) {
         $model = $this->getModelFromSerializedId($serializedId);
     } else {
         $dataProvider = $environment->getDataProvider();
         $model = $dataProvider->getEmptyModel();
     }
     $widgetManager = new ContaoWidgetManager($environment, $model);
     // Process input and update changed properties.
     $treeType = substr($property->getWidgetType(), 0, 4);
     $propertyValue = $this->getTreeValue($treeType, $propertyValue);
     if ($treeType == 'file' || $treeType == 'page') {
         $extra = $property->getExtra();
         if (is_array($propertyValue) && !isset($extra['multiple'])) {
             $propertyValue = $propertyValue[0];
         } else {
             $propertyValue = implode(',', (array) $propertyValue);
         }
     }
     $propertyValues->setPropertyValue($fieldName, $propertyValue);
     $widgetManager->processInput($propertyValues);
     $model->setProperty($fieldName, $propertyValues->getPropertyValue($fieldName));
     $widget = $widgetManager->getWidget($fieldName);
     return $widget;
 }
示例#2
0
 /**
  * Validate widgets.
  *
  * @return void
  */
 private function validateWidgets()
 {
     $this->widgetManager->processInput($this->propertyValues);
 }
示例#3
0
 /**
  * Process input and return all modified properties or null if there is no input.
  *
  * @param ContaoWidgetManager $widgetManager The widget manager in use.
  *
  * @return null|PropertyValueBag
  */
 protected function processInput($widgetManager)
 {
     $input = $this->getEnvironment()->getInputProvider();
     if ($input->getValue('FORM_SUBMIT') == $this->getDataDefinition()->getName()) {
         $propertyValues = new PropertyValueBag();
         $propertyNames = array_intersect($this->getDataDefinition()->getPropertiesDefinition()->getPropertyNames(), $input->getValue('FORM_INPUTS'));
         // Process input and update changed properties.
         foreach ($propertyNames as $propertyName) {
             $propertyValue = $input->hasValue($propertyName) ? $input->getValue($propertyName, true) : null;
             $propertyValues->setPropertyValue($propertyName, $propertyValue);
         }
         $widgetManager->processInput($propertyValues);
         return $propertyValues;
     }
     return null;
 }