Example #1
0
 /**
  * {@inheritDoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $choices = [];
     foreach ($this->providerPool->getValues() as $alias => $value) {
         $choices[$alias] = $value->getLabel();
     }
     $resolver->setDefaults(['label' => 'Type of value', 'choices' => $choices]);
 }
Example #2
0
 /**
  * Transforms the provider values into a discriminatorMap
  *
  * @return array
  */
 public function getDiscriminatorMap()
 {
     $map = array();
     foreach ($this->pool->getValues() as $alias => $value) {
         $map[$alias . 'value'] = $value->getEntity();
     }
     return $map;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('valueType', ValueProviderType::class, ['label' => 'attribute.value_type', 'attr' => ['placeholder' => 'form.value_type.placeholder', 'help_text' => 'form.value_type.help_text']])->add('displayName', TextType::class, ['label' => 'attribute.display_name', 'attr' => ['class' => 'slugify', 'data-slugify-target' => '.slugify-target-' . $builder->getName(), 'data-slugify-separator' => '_', 'placeholder' => 'form.display_name.placeholder', 'help_text' => 'form.display_name.help_text', 'widget_col' => 6]])->add('name', TextType::class, ['label' => 'attribute.name', 'attr' => ['class' => 'slugify-target-' . $builder->getName(), 'placeholder' => 'form.name.placeholder', 'help_text' => 'form.name.help_text', 'widget_col' => 6]])->add('description', TextType::class, ['required' => false, 'label' => 'attribute.description', 'attr' => ['help_text' => 'form.description.help_text']])->add('sort', IntegerType::class, ['label' => 'attribute.sort', 'attr' => ['help_text' => 'form.sort.help_text', 'widget_col' => 2], 'empty_data' => 0, 'required' => false])->add('required', ChoiceType::class, ['choices' => [false => 'Not required', true => 'Required'], 'label' => 'Required', 'required' => true]);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($builder) {
         $attribute = $event->getData();
         $form = $event->getForm();
         if ($attribute) {
             $parametersForm = $builder->create('parameters', FormType::class, ['auto_initialize' => false]);
             $this->providerPool->getValue($attribute->getValueType())->buildParametersForm($parametersForm);
             if (count($parametersForm->all())) {
                 $form->add($parametersForm->getForm());
             }
         }
         if ($attribute && in_array($attribute->getValueType(), ['checklist', 'select', 'radio'])) {
             // TODO Use Symfony's CollectionType here
             $form->add('options', CollapsibleCollectionType::class, ['allow_add' => true, 'allow_delete' => true, 'type' => OptionType::class]);
         }
     });
 }
Example #4
0
 /**
  * Creates empty entities for non-persisted attributes.
  *
  * @param ValueSetInterface $valueSet
  *
  * @return array
  */
 public function replaceEmptyValues(ValueSetInterface $valueSet)
 {
     // collect persisted attributevalues
     $persistedAttributes = array();
     foreach ($valueSet->getValues() as $value) {
         $persistedAttributes[] = $value->getAttribute();
     }
     $newValues = array();
     // Create empty entities for missing attributes
     $missingAttributes = array_diff($valueSet->getAttributes()->toArray(), $persistedAttributes);
     foreach ($missingAttributes as $attribute) {
         $provider = $this->providerPool->getValue($attribute->getValueType());
         $valueClass = $provider->getEntity();
         $value = new $valueClass();
         $valueSet->addValue($value);
         $value->setValueSet($valueSet);
         $value->setAttribute($attribute);
         $newValues[] = $value;
     }
     return $newValues;
 }
Example #5
0
 /**
  * {@inheritDoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $provider = $this->providerPool->getValue($options['attribute']->getValueType());
     $provider->buildForm($builder, $options);
 }