Esempio n. 1
0
 /**
  * Build the field sets.
  *
  * @param ContaoWidgetManager $widgetManager  The widget manager in use.
  *
  * @param PaletteInterface    $palette        The palette to use.
  *
  * @param PropertyValueBag    $propertyValues The property values.
  *
  * @return array
  */
 protected function buildFieldSet($widgetManager, $palette, $propertyValues)
 {
     $environment = $this->getEnvironment();
     $definition = $this->getDataDefinition();
     $translator = $environment->getTranslator();
     $propertyDefinitions = $definition->getPropertiesDefinition();
     $isAutoSubmit = $environment->getInputProvider()->getValue('SUBMIT_TYPE') === 'auto';
     $legendStates = $this->getLegendStates();
     $fieldSets = array();
     $first = true;
     foreach ($palette->getLegends() as $legend) {
         $legendName = $translator->translate($legend->getName() . '_legend', $definition->getName());
         $fields = array();
         $properties = $legend->getProperties($this->model, $propertyValues);
         if (!$properties) {
             continue;
         }
         $legendVisible = $this->isLegendVisible($legend, $legendStates);
         foreach ($properties as $property) {
             $this->ensurePropertyExists($property->getName(), $propertyDefinitions);
             // If this property is invalid, fetch the error.
             if (!$isAutoSubmit && $propertyValues && $propertyValues->hasPropertyValue($property->getName()) && $propertyValues->isPropertyValueInvalid($property->getName())) {
                 $this->errors = array_merge($this->errors, $propertyValues->getPropertyValueErrors($property->getName()));
                 // Force legend open on error.
                 $legendVisible = true;
             }
             $fields[] = $widgetManager->renderWidget($property->getName(), $isAutoSubmit, $propertyValues);
         }
         $fieldSet['label'] = $legendName;
         $fieldSet['class'] = $this->getLegendClass($first, $legendVisible);
         $fieldSet['palette'] = implode('', $fields);
         $fieldSet['legend'] = $legend->getName();
         $fieldSets[] = $fieldSet;
         $first = false;
     }
     return $fieldSets;
 }
 /**
  * Build the field sets.
  *
  * @param WidgetManager    $widgetManager  The widget manager in use.
  *
  * @param PaletteInterface $palette        The palette to use.
  *
  * @param PropertyValueBag $propertyValues The property values.
  *
  * @return array
  */
 private function buildFieldSet($widgetManager, $palette, $propertyValues)
 {
     $propertyDefinitions = $this->definition->getPropertiesDefinition();
     $isAutoSubmit = $this->environment->getInputProvider()->getValue('SUBMIT_TYPE') === 'auto';
     $fieldSets = [];
     $first = true;
     foreach ($palette->getLegends() as $legend) {
         $legendName = $this->translator->translate($legend->getName() . '_legend', $this->definition->getName());
         $fields = [];
         $hidden = [];
         $properties = $legend->getProperties($this->model, $propertyValues);
         if (!$properties) {
             continue;
         }
         foreach ($properties as $property) {
             $propertyName = $property->getName();
             $this->ensurePropertyExists($propertyName, $propertyDefinitions);
             // If this property is invalid, fetch the error.
             if (!$isAutoSubmit && $propertyValues && $propertyValues->hasPropertyValue($propertyName) && $propertyValues->isPropertyValueInvalid($propertyName)) {
                 $this->errors = array_merge($this->errors, $propertyValues->getPropertyValueErrors($propertyName));
             }
             $fields[] = $widgetManager->renderWidget($propertyName, $isAutoSubmit, $propertyValues);
             $hidden[] = sprintf('<input type="hidden" name="FORM_INPUTS[]" value="%s">', $propertyName);
         }
         $fieldSet['label'] = $legendName;
         $fieldSet['class'] = $first ? 'tl_tbox' : 'tl_box';
         $fieldSet['palette'] = implode('', $hidden) . implode('', $fields);
         $fieldSet['legend'] = $legend->getName();
         $fieldSets[] = $fieldSet;
         $first = false;
     }
     return $fieldSets;
 }