src/CustomBundle/Form/TopPageRestaurantSearchType.php line 14

Open in your IDE?
  1. <?php
  2. namespace CustomBundle\Form;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\Extension\Core\Type as InputType;
  5. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. use Symfony\Component\Form\FormEvent;
  8. use Symfony\Component\Form\FormEvents;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use AppBundle\Validator\Constraints as CustomAssert;
  12. class TopPageRestaurantSearchType extends AbstractType
  13. {
  14.     public function getBlockPrefix()
  15.     {
  16.         return '';
  17.     }
  18.     public function buildForm(FormBuilderInterface $builder, array $options)
  19.     {
  20.         $genres $options['genres'];
  21.         $time_by_cars $options['time_by_cars'];
  22.         $scenes $options['scenes'];
  23.         $features $options['features'];
  24.         $builder->add('genre'InputType\ChoiceType::class, [
  25.             'required' => false,
  26.             'label' => 'ジャンル',
  27.             'constraints' => [],
  28.             'expanded' => false,
  29.             'multiple' => false,
  30.             'placeholder' => 'ジャンル',
  31.             'choices' => array_flip($genres)
  32.         ]);
  33.         $builder->add('time_by_car'InputType\ChoiceType::class, [
  34.             'required' => false,
  35.             'label' => '車での距離',
  36.             'constraints' => [],
  37.             'expanded' => false,
  38.             'multiple' => false,
  39.             'placeholder' => 'ジブリパークからの距離',
  40.             'choices' => array_flip($time_by_cars)
  41.         ]);
  42.         $builder->add('scene'InputType\ChoiceType::class, [
  43.             'required' => false,
  44.             'label' => '利用シーン',
  45.             'constraints' => [],
  46.             'expanded' => false,
  47.             'multiple' => false,
  48.             'placeholder' => '利用シーン',
  49.             'choices' => array_flip($scenes)
  50.         ]);
  51.         $builder->add('feature'InputType\ChoiceType::class, [
  52.             'required' => false,
  53.             'label' => '特徴',
  54.             'constraints' => [],
  55.             'expanded' => false,
  56.             'multiple' => false,
  57.             'placeholder' => '特徴',
  58.             'choices' => array_flip($features)
  59.         ]);
  60.     }
  61.     public function configureOptions(OptionsResolver $resolver)
  62.     {
  63.         parent::configureOptions($resolver);
  64.         $resolver->setDefaults([
  65.             'genres' => null,
  66.             'time_by_cars' => null,
  67.             'scenes' => null,
  68.             'features' => null,
  69.             'allow_extra_fields' => true// ?page=のエラーを出さない用
  70.         ]);
  71.     }
  72. }