app/Plugin/FreeSample/Form/Type/HistoryType.php line 25

Open in your IDE?
  1. <?php
  2. namespace Plugin\FreeSample\Form\Type;
  3. use Plugin\FreeSample\Entity\History;
  4. use Symfony\Component\OptionsResolver\OptionsResolver;
  5. use Eccube\Common\EccubeConfig;
  6. use Eccube\Form\Type\AddressType;
  7. use Eccube\Form\Type\KanaType;
  8. use Eccube\Form\Type\NameType;
  9. use Eccube\Form\Type\PhoneNumberType;
  10. use Eccube\Form\Type\PostalType;
  11. use Eccube\Form\Validator\Email;
  12. use Symfony\Component\Form\AbstractType;
  13. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  15. use Symfony\Component\Form\FormBuilderInterface;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. class HistoryType extends AbstractType
  18. {
  19.     protected $eccubeConfig;
  20.     public function __construct(EccubeConfig $eccubeConfig)
  21.     {
  22.         $this->eccubeConfig $eccubeConfig;
  23.     }
  24.     /**
  25.      * {@inheritdoc}
  26.      */
  27.     public function buildForm(FormBuilderInterface $builder, array $options)
  28.     {
  29.         $builder
  30.             ->add('name'NameType::class, [
  31.                 'required' => true,
  32.                 'constraints' => [
  33.                     new Assert\NotBlank(),
  34.                 ],
  35.             ])
  36.             ->add('kana'KanaType::class, [
  37.                 'required' => true,
  38.                 'constraints' => [
  39.                     new Assert\NotBlank(),
  40.                 ],
  41.             ])
  42.             ->add('postal_code'PostalType::class, [
  43.                 'required' => false,
  44.             ])
  45.             ->add('address'AddressType::class, [
  46.                 'required' => false,
  47.             ])
  48.             ->add('phone_number'PhoneNumberType::class, [
  49.                 'required' => false,
  50.             ])
  51.             ->add('email'EmailType::class, [
  52.                 'constraints' => [
  53.                     new Assert\NotBlank(),
  54.                     new Email(nullnull$this->eccubeConfig['eccube_rfc_email_check'] ? 'strict' null),
  55.                 ],
  56.             ])
  57.             ->add('contents'TextareaType::class, [
  58.                 'required' => false,
  59.                 'constraints' => [
  60.                     new Assert\NotBlank(),
  61.                     new Assert\Length([
  62.                         'max' => $this->eccubeConfig['eccube_lltext_len'],
  63.                     ])
  64.                 ],
  65.             ]);
  66.     }
  67.     /**
  68.      * {@inheritdoc}
  69.      */
  70.     public function historyureOptions(OptionsResolver $resolver)
  71.     {
  72.         $resolver->setDefaults([
  73.             'data_class' => History::class,
  74.         ]);
  75.     }
  76. }