/**
  * Build a data definition and store it into the environments container.
  *
  * @param \ContaoCommunityAlliance\DcGeneral\DataDefinition\ContainerInterface $container
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function build(ContainerInterface $container, BuildDataDefinitionEvent $event)
 {
     if (!$this->loadDca($container->getName(), $this->getDispatcher())) {
         return;
     }
     if ($container->hasDefinition(PalettesDefinitionInterface::NAME)) {
         $palettesDefinition = $container->getDefinition(PalettesDefinitionInterface::NAME);
     } else {
         $palettesDefinition = new DefaultPalettesDefinition();
         $container->setDefinition(PalettesDefinitionInterface::NAME, $palettesDefinition);
     }
     $parser = new LegacyPalettesParser();
     $selectorFieldNames = (array) $this->getFromDca('palettes/__selector__');
     $palettesDca = (array) $this->getFromDca('metapalettes');
     $subPalettesDca = (array) $this->getFromDca('metasubpalettes');
     $subSelectPalettesDca = (array) $this->getFromDca('metasubselectpalettes');
     // extend the selector field names with subpalettes field names
     $selectorFieldNames = array_merge($selectorFieldNames, array_keys($subPalettesDca));
     $subSelectPalettes = $this->parseSubSelectPalettes($subSelectPalettesDca);
     $subPalettes = $this->parseSubPalettes($parser, $subPalettesDca, $selectorFieldNames);
     $palettes = $this->parsePalettes($palettesDefinition, $parser, $palettesDca, $subPalettes, $subSelectPalettes, $selectorFieldNames);
     if (empty($palettes)) {
         return;
     }
     $palettesDefinition->addPalettes($palettes);
 }
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * Check if the contect of the event is a allowed one.
  *
  * @param ContainerInterface $dataDefinition The data definition from the environment.
  *
  * @param string             $propertyName   The current property name.
  *
  * @param ModelInterface     $model          The current model.
  *
  * @return bool True => It is a allowed one | False => nope
  */
 protected function isAllowedContext($dataDefinition, $propertyName, $model)
 {
     // Check the name of the data def.
     if ($dataDefinition->getName() !== 'tl_metamodel_filtersetting') {
         return false;
     }
     // Check the name of the property.
     if ($propertyName !== 'attr_id2') {
         return false;
     }
     // Check the type.
     if ($model->getProperty('type') !== 'range' && $model->getProperty('type') !== 'rangedate') {
         return false;
     }
     // At the end, return true.
     return true;
 }
 /**
  * Parse the defined properties and populate the definition.
  *
  * @param ContainerInterface $container The container where the data shall be stored.
  *
  * @return void
  */
 protected function parseProperties(ContainerInterface $container)
 {
     if ($container->hasPropertiesDefinition()) {
         $definition = $container->getPropertiesDefinition();
     } else {
         $definition = new DefaultPropertiesDefinition();
         $container->setPropertiesDefinition($definition);
     }
     foreach ((array) $this->getFromDca('fields') as $propName => $propInfo) {
         if ($definition->hasProperty($propName)) {
             $property = $definition->getProperty($propName);
         } else {
             $property = new DefaultProperty($propName);
             $definition->addProperty($property);
         }
         $this->parseSingleProperty($property, $propInfo);
     }
 }
 /**
  * Parse and build the backend view definition for the old Contao2 backend view.
  *
  * This method expects to find an instance of Contao2BackendViewDefinitionInterface in the container.
  *
  * @param ContainerInterface $container The container where the data shall be stored.
  *
  * @return void
  *
  * @throws DcGeneralInvalidArgumentException If the stored definition in the container is of invalid type.
  */
 protected function parseBackendView(ContainerInterface $container)
 {
     if ($container->hasDefinition(Contao2BackendViewDefinitionInterface::NAME)) {
         $view = $container->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
     } else {
         $view = new Contao2BackendViewDefinition();
         $container->setDefinition(Contao2BackendViewDefinitionInterface::NAME, $view);
     }
     if (!$view instanceof Contao2BackendViewDefinitionInterface) {
         throw new DcGeneralInvalidArgumentException('Configured BackendViewDefinition does not implement Contao2BackendViewDefinitionInterface.');
     }
     $this->parseListing($view);
 }