<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Customize\Form\Type;
use Eccube\Common\EccubeConfig;
use Eccube\Form\Type\AddressType;
use Eccube\Form\Type\PhoneNumberType;
use Eccube\Form\Type\PostalType;
use Eccube\Form\Type\RepeatedEmailType;
use Eccube\Form\Type\SimpleAddressType;
use Eccube\Form\Validator\Email;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\RadioType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class ContactType
*/
class ContactType extends AbstractType
{
/**
* @var EccubeConfig
*/
protected $eccubeConfig;
/**
* ForgotType constructor.
*
* @param EccubeConfig $eccubeConfig
*/
public function __construct(EccubeConfig $eccubeConfig)
{
$this->eccubeConfig = $eccubeConfig;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** フォーム項目設定 */
#region
$builder
->add('company_name', TextType::class, [
'required' => true,
])
->add('representative_name', TextType::class, [
'required' => true,
])
->add('contact_person_name', TextType::class, [
'required' => false,
])
->add('postal_code', PostalType::class)
->add('address', SimpleAddressType::class)
->add('phone_number', PhoneNumberType::class, [
'required' => true,
])
->add('email', EmailType::class)
->add('fax_number', PhoneNumberType::class, [
'required' => false,
])
->add('url', UrlType::class, [
'required' => false,
])
->add('business_form', ChoiceType::class, [
'choices' => [
'個人事業' => '個人事業',
'法人' => '法人',
'その他' => 'その他',
],
'required' => false,
'multiple' => false,
'expanded' => false,
'mapped' => true,
'placeholder' => '選択してください',
])
->add('business_form_other', TextType::class, [
'required' => false,
])
->add('sales_form', ChoiceType::class, [
'choices' => [
'実店舗' => '実店舗',
'ネット' => 'ネット',
'卸売り' => '卸売り',
'その他' => 'その他',
],
'required' => false,
'multiple' => false,
'expanded' => false,
'mapped' => true,
'placeholder' => '選択してください',
])
->add('sales_form_other', TextType::class, [
'required' => false,
])
->add('use_case', ChoiceType::class, [
'choices' => [
'出品' => '出品',
'仕入' => '仕入',
'両方' => '両方',
'検討中' => '検討中',
],
'required' => true,
'multiple' => false,
'expanded' => false,
'mapped' => true,
'placeholder' => '選択してください',
])
->add('selling_schedule', ChoiceType::class, [
'choices' => [
'楽器' => '楽器',
'その他' => 'その他',
],
'required' => false,
'multiple' => false,
'expanded' => false,
'mapped' => true,
'placeholder' => '選択してください',
])
->add('selling_schedule_other', TextType::class, [
'required' => false,
])
->add('experience', ChoiceType::class, [
'choices' => [
'初めて' => '初めて',
'ネットは初めて' => 'ネットは初めて',
'他に参加有' => '他に参加有',
],
'required' => false,
'multiple' => false,
'expanded' => false,
'mapped' => true,
'placeholder' => '選択してください',
])
->add('chance', ChoiceType::class, [
'choices' => [
'ご紹介' => 'ご紹介',
'ネット' => 'ネット',
],
'required' => false,
'multiple' => false,
'expanded' => true,
'mapped' => true,
'placeholder' => false,
])
->add('chance_other', TextType::class, [
'required' => false,
])
->add('remarks', TextareaType::class, [
'required' => false,
'attr' => [
'maxlength' => 1000,
],
]);
#endregion
/** フォームリスナー */
#region
$builder
->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event){
$businessForm = $event->getForm()->get('business_form');
$businessFormOther = $event->getForm()->get('business_form_other');
if( $businessForm->getData() === "その他" && empty($businessFormOther->getData())){
$businessFormOther->addError(new FormError('事業形態が「その他」の場合はご記入ください'));
}
$salesForm = $event->getForm()->get('sales_form');
$salesFormOther = $event->getForm()->get('sales_form_other');
if( $salesForm->getData() === "その他" && empty($salesFormOther->getData())){
$salesFormOther->addError(new FormError('営業形態が「その他」の場合はご記入ください'));
}
$sellingSchedule = $event->getForm()->get('selling_schedule');
$sellingScheduleOther = $event->getForm()->get('selling_schedule_other');
if( $sellingSchedule->getData() === "その他" && empty($sellingScheduleOther->getData())){
$sellingScheduleOther->addError(new FormError('売買予定商品が「その他」の場合はご記入ください'));
}
$chance = $event->getForm()->get('chance');
$chanceOther = $event->getForm()->get('chance_other');
if( $chance->getData() === "ご紹介" && empty($chanceOther->getData())){
$chanceOther->addError(new FormError('ご参加のきっかけが「ご紹介」の場合はご記入ください'));
}
});
#endregion
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'forgot';
}
}