src/DcSiteBundle/Form/TiresConfiguratorType.php line 15

Open in your IDE?
  1. <?php
  2. namespace DcSiteBundle\Form;
  3. use CoreBundle\Form\CoreFormsType;
  4. use DcSiteBundle\Model\Tires;
  5. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  6. use Symfony\Component\Form\Extension\Core\Type\TextType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\OptionsResolver\OptionsResolver;
  9. use Symfony\Contracts\Translation\TranslatorInterface;
  10. class TiresConfiguratorType extends CoreFormsType
  11. {
  12.     public function buildForm(FormBuilderInterface $builder, array $options)
  13.     {
  14.         parent::buildForm($builder$options);
  15.         /** @var TranslatorInterface $translator */
  16.         $translator $options['translator'];
  17.         $builder
  18.             ->add('tiresType'ChoiceType::class, [
  19.                 'mapped' => false,
  20.                 'required' => false,
  21.                 'expanded' => true,
  22.                 'choices' => array_flip(Tires::getTireType(null$translator->getLocale())),
  23.                 'data' => 1,
  24.             ])
  25.             ->add('vin'TextType::class, [
  26.                 'label' => false,
  27.                 'mapped' => false,
  28.                 'required' => false,
  29.                 'attr' => [
  30.                     'placeholder' => $translator->trans('form.vin_your_car', [], 'dc_base'),
  31.                     'class' => 'form-control',
  32.                 ]
  33.             ])
  34.             ->add('diameter'ChoiceType::class, [
  35.                 'mapped' => false,
  36.                 'required' => false,
  37.                 'label' => false,
  38.                 'placeholder' => $translator->trans('configurator.tires.diameter', [], 'dc_base'),
  39.                 'choices' => Tires::getDiameter(),
  40.                 'attr' => [
  41.                     'class' => 'form-control',
  42.                 ],
  43.                 'choice_attr' => function($choice$key$value) {
  44.                     if ($key == 17 || $key == 19 || $key == 20) {
  45.                         return ['style' => 'font-weight: bold'];
  46.                     }
  47.                     return [];
  48.                 },
  49.                 'preferred_choices' => ['17''19''20'],
  50.             ])
  51.             ->add('width'ChoiceType::class, [
  52.                 'mapped' => false,
  53.                 'required' => false,
  54.                 'label' => false,
  55.                 'placeholder' => $translator->trans('configurator.tires.width', [], 'dc_base'),
  56.                 'choices' => Tires::getWidth(),
  57.                 'attr' => [
  58.                     'class' => 'form-control',
  59.                 ],
  60.                 'choice_attr' => function($choice$key$value) {
  61.                     if ($key == 225 || $key == 235) {
  62.                         return ['style' => 'font-weight: bold'];
  63.                     }
  64.                     return [];
  65.                 },
  66.                 'preferred_choices' => ['225''235'],
  67.             ])
  68.             ->add('profile'ChoiceType::class, [
  69.                 'mapped' => false,
  70.                 'required' => false,
  71.                 'label' => false,
  72.                 'placeholder' => $translator->trans('configurator.tires.profile_height', [], 'dc_base'),
  73.                 'choices' => Tires::getProfileHeight(),
  74.                 'attr' => [
  75.                     'class' => 'form-control',
  76.                 ],
  77.             ])
  78.         ;
  79.     }
  80.     public function configureOptions(OptionsResolver $resolver)
  81.     {
  82.         parent::configureOptions($resolver);
  83.         $resolver->setDefined('dealer')
  84.             ->setDefault('captcha_type','buy_spare_parts_form');
  85.     }
  86. }