<?php
namespace Plugin\ApplyForSampleMagazine42\Form\Type;
use Eccube\Common\EccubeConfig;
use Eccube\Form\Type\AddressType;
use Eccube\Form\Type\KanaType;
use Eccube\Form\Type\NameType;
use Eccube\Form\Type\PhoneNumberType;
use Eccube\Form\Type\PostalType;
use Eccube\Form\Validator\Email;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;
class ApplyType extends AbstractType
{
/**
* @var EccubeConfig
*/
protected $eccubeConfig;
/**
* ContactType constructor.
*
* @param EccubeConfig $eccubeConfig
*/
public function __construct(EccubeConfig $eccubeConfig)
{
$this->eccubeConfig = $eccubeConfig;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', NameType::class, [
'required' => true,
])
->add('kana', KanaType::class, [
'required' => true,
])
->add('company_name', TextType::class, [
'required' => false,
'constraints' => [
new Assert\Length([
'max' => $this->eccubeConfig['eccube_stext_len'],
]),
],
])
->add('shipping_type', ChoiceType::class, [
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
'choices' => [
'自宅' => 1,
'職場' => 2
],
'expanded' => true,
])
->add('postal_code', PostalType::class, [
'required' => true,
])
->add('address', AddressType::class, [
'required' => true,
])
->add('phone_number', PhoneNumberType::class, [
'required' => true,
])
->add('email', EmailType::class, [
'constraints' => [
new Assert\NotBlank(),
new Email(null, null, $this->eccubeConfig['eccube_rfc_email_check'] ? 'strict' : null),
],
])
->add('age', ChoiceType::class, [
'required' => false,
'choices' => [
'10代' => 1,
'20代' => 2,
'30代' => 3,
'40代' => 4,
'50代' => 5,
'60代以上' => 6,
],
'placeholder' => false,
'expanded' => true,
])
->add('company_school_name', TextType::class, [
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
])
->add('contents1', TextareaType::class, [
'required' => false,
'constraints' => [
new Assert\Length([
'max' => $this->eccubeConfig['eccube_lltext_len'],
])
],
])
->add('contents2', TextareaType::class, [
'required' => false,
'constraints' => [
new Assert\Length([
'max' => $this->eccubeConfig['eccube_lltext_len'],
])
],
])
;
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'apply';
}
}