app/Customize/Form/Type/UserType.php line 35

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Customize\Form\Type;
  13. use Eccube\Form\Type\NameType;
  14. use Eccube\Form\Type\KanaType;
  15. use Eccube\Form\Type\PhoneNumberType;
  16. use Symfony\Component\Form\AbstractType;
  17. use Symfony\Component\Form\FormBuilderInterface;
  18. use Symfony\Component\OptionsResolver\OptionsResolver;
  19. use Symfony\Component\Validator\Constraints as Assert;
  20. use Customize\Entity\User;
  21. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  22. use Eccube\Entity\Master\Pref;
  23. use Eccube\Form\Type\AddressType;
  24. use Eccube\Form\Type\PostalType;
  25. use Customize\Entity\Master\Religion;
  26. use Customize\Entity\Master\BuddhistSect;
  27. use Symfony\Component\Form\Extension\Core\Type\TextType;
  28. use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
  29. use Eccube\Common\EccubeConfig;
  30. /** @extends AbstractType<User> */
  31. class UserType extends AbstractType
  32. {
  33.         /**
  34.      * @var EccubeConfig
  35.      */
  36.     protected EccubeConfig $eccubeConfig;
  37.     /**
  38.      * EntryType constructor.
  39.      *
  40.      * @param EccubeConfig $eccubeConfig
  41.      */
  42.     public function __construct(EccubeConfig $eccubeConfig)
  43.     {
  44.         $this->eccubeConfig $eccubeConfig;
  45.     }
  46.     /**
  47.      * {@inheritdoc}
  48.      *
  49.      * @param FormBuilderInterface<User|null> $builder
  50.      * @param array<string, mixed> $options
  51.      * @return void
  52.      */
  53.     public function buildForm(FormBuilderInterface $builder, array $options)
  54.     {
  55.         $builder
  56.             ->add('name'NameType::class, [
  57.                 'required' => true,
  58.             ])
  59.             ->add('kana'KanaType::class, [
  60.                 'required' => false,
  61.             ])
  62.             ->add('phone_number'PhoneNumberType::class, [
  63.                 'required' => true,
  64.                 'constraints' => [
  65.                     new Assert\Length([
  66.                         'min' => 10,
  67.                         'max' => 11,
  68.                         'minMessage' => 'form_error.phone_number_min',
  69.                         'maxMessage' => 'form_error.phone_number_max',
  70.                     ]),
  71.                 ],
  72.             ])
  73.             ->add('SearchingPrefs'EntityType::class, [
  74.                 'class' => Pref::class,
  75.                 'choice_label' => 'name',
  76.                 'expanded' => true,
  77.                 'multiple' => true,
  78.                 'required' => false,
  79.             ])
  80.             ->add('postal_code'PostalType::class, [
  81.                 'required' => false,
  82.             ])
  83.             ->add('address'AddressType::class, [
  84.                 'required' => false,
  85.             ])
  86.             ->add('company_phone_number'PhoneNumberType::class, [
  87.                 'required' => false,
  88.                 'constraints' => [
  89.                     new Assert\Length([
  90.                         'min' => 10,
  91.                         'max' => 11,
  92.                         'minMessage' => 'form_error.phone_number_min',
  93.                         'maxMessage' => 'form_error.phone_number_max',
  94.                     ]),
  95.                 ],
  96.             ])
  97.             ->add('Religions'EntityType::class, [
  98.                 'class' => Religion::class,
  99.                 'choice_label' => 'name',
  100.                 'expanded' => true,
  101.                 'multiple' => true,
  102.                 'required' => false,
  103.             ])
  104.             ->add('religion_other'TextType::class, [
  105.                 'required' => false,
  106.             ])
  107.             ->add('BuddhistSects'EntityType::class, [
  108.                 'class' => BuddhistSect::class,
  109.                 'choice_label' => 'name',
  110.                 'expanded' => true,
  111.                 'multiple' => true,
  112.                 'required' => false,
  113.             ])
  114.             ->add('buddhist_sect_other'TextType::class, [
  115.                 'required' => false,
  116.             ])
  117.             ->add('EmergencyContact'EmergencyContactType::class, [
  118.                 'required' => false,
  119.             ])
  120.             ->add('birth'BirthdayType::class, [
  121.                 'required' => false,
  122.                 'input' => 'datetime',
  123.                 'years' => range(date('Y'), date('Y') - $this->eccubeConfig['eccube_birth_max']),
  124.                 'widget' => 'choice',
  125.                 'placeholder' => ['year' => '----''month' => '--''day' => '--'],
  126.                 'constraints' => [
  127.                     new Assert\LessThanOrEqual([
  128.                         'value' => date('Y-m-d'strtotime('-1 day')),
  129.                         'message' => 'form_error.select_is_future_or_now_date',
  130.                     ]),
  131.                 ],
  132.             ])
  133.             ->add('company_name'TextType::class, [
  134.                 'required' => false,
  135.                 'constraints' => [
  136.                     new Assert\Length([
  137.                         'max' => $this->eccubeConfig['eccube_stext_len'],
  138.                     ]),
  139.                 ],
  140.             ]);
  141.     }
  142.     /**
  143.      * {@inheritdoc}
  144.      */
  145.     public function configureOptions(OptionsResolver $resolver): void
  146.     {
  147.         $resolver->setDefaults([
  148.             'data_class' => User::class,
  149.         ]);
  150.     }
  151. }