<?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\Form\Type\NameType;
use Eccube\Form\Type\KanaType;
use Eccube\Form\Type\PhoneNumberType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;
use Customize\Entity\User;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Eccube\Entity\Master\Pref;
use Eccube\Form\Type\AddressType;
use Eccube\Form\Type\PostalType;
use Customize\Entity\Master\Religion;
use Customize\Entity\Master\BuddhistSect;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
use Eccube\Common\EccubeConfig;
/** @extends AbstractType<User> */
class UserType extends AbstractType
{
/**
* @var EccubeConfig
*/
protected EccubeConfig $eccubeConfig;
/**
* EntryType constructor.
*
* @param EccubeConfig $eccubeConfig
*/
public function __construct(EccubeConfig $eccubeConfig)
{
$this->eccubeConfig = $eccubeConfig;
}
/**
* {@inheritdoc}
*
* @param FormBuilderInterface<User|null> $builder
* @param array<string, mixed> $options
* @return void
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', NameType::class, [
'required' => true,
])
->add('kana', KanaType::class, [
'required' => false,
])
->add('phone_number', PhoneNumberType::class, [
'required' => true,
'constraints' => [
new Assert\Length([
'min' => 10,
'max' => 11,
'minMessage' => 'form_error.phone_number_min',
'maxMessage' => 'form_error.phone_number_max',
]),
],
])
->add('SearchingPrefs', EntityType::class, [
'class' => Pref::class,
'choice_label' => 'name',
'expanded' => true,
'multiple' => true,
'required' => false,
])
->add('postal_code', PostalType::class, [
'required' => false,
])
->add('address', AddressType::class, [
'required' => false,
])
->add('company_phone_number', PhoneNumberType::class, [
'required' => false,
'constraints' => [
new Assert\Length([
'min' => 10,
'max' => 11,
'minMessage' => 'form_error.phone_number_min',
'maxMessage' => 'form_error.phone_number_max',
]),
],
])
->add('Religions', EntityType::class, [
'class' => Religion::class,
'choice_label' => 'name',
'expanded' => true,
'multiple' => true,
'required' => false,
])
->add('religion_other', TextType::class, [
'required' => false,
])
->add('BuddhistSects', EntityType::class, [
'class' => BuddhistSect::class,
'choice_label' => 'name',
'expanded' => true,
'multiple' => true,
'required' => false,
])
->add('buddhist_sect_other', TextType::class, [
'required' => false,
])
->add('EmergencyContact', EmergencyContactType::class, [
'required' => false,
])
->add('birth', BirthdayType::class, [
'required' => false,
'input' => 'datetime',
'years' => range(date('Y'), date('Y') - $this->eccubeConfig['eccube_birth_max']),
'widget' => 'choice',
'placeholder' => ['year' => '----', 'month' => '--', 'day' => '--'],
'constraints' => [
new Assert\LessThanOrEqual([
'value' => date('Y-m-d', strtotime('-1 day')),
'message' => 'form_error.select_is_future_or_now_date',
]),
],
])
->add('company_name', TextType::class, [
'required' => false,
'constraints' => [
new Assert\Length([
'max' => $this->eccubeConfig['eccube_stext_len'],
]),
],
]);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}