Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Form\EntityType;
- use App\Entity\Person;
- use App\EventSubscriber\NumberTypeByCitizenshipSubscriber;
- use App\EventSubscriber\CityListByCountrySubscriber;
- use App\Form\AdminType\AdminAvailabilityType;
- use App\Form\AdminType\AdminCreatedAtType;
- use App\Form\AdminType\AdminCreatedByType;
- use App\Form\AdminType\AdminUpdatedAtType;
- use App\Form\AdminType\AdminUpdatedByType;
- use App\Form\AdminType\AdminVisibilityType;
- use App\Form\BaseType\BaseCitizenshipType;
- use App\Form\BaseType\BaseCollectionsType;
- use App\Form\BaseType\BaseCountryType;
- use App\Form\BaseType\BaseInputType;
- use App\Form\FormType\FormBirthdayType;
- use App\Form\FormType\FormGenderType;
- use App\Form\FormType\FormNameType;
- use Symfony\Component\Form\AbstractType;
- use Symfony\Component\Form\FormBuilderInterface;
- use Symfony\Component\OptionsResolver\OptionsResolver;
- use Symfony\Component\Validator\Constraints\NotBlank;
- /**
- * Defines the form used to create or update Person entity.
- */
- class PersonType extends AbstractType
- {
- /**
- * {@inheritdoc}
- */
- public function buildForm(FormBuilderInterface $builder, array $options)
- {
- /** @var Person|null $person */
- $builder
- ->add('hidden', AdminVisibilityType::class)
- ->add('locked', AdminAvailabilityType::class)
- ->add('createdBy', AdminCreatedByType::class)
- ->add('updatedBy', AdminUpdatedByType::class)
- ->add('createdAt', AdminCreatedAtType::class)
- ->add('updatedAt', AdminUpdatedAtType::class)
- ->add('firstName', FormNameType::class, [
- 'label' => 'label.firstName',
- ])
- ->add('middleName', FormNameType::class, [
- 'label' => 'label.middleName'
- ])
- ->add('lastName', FormNameType::class, [
- 'label' => 'label.lastName'
- ])
- ->add('gender', FormGenderType::class)
- ->add('citizenship', BaseCitizenshipType::class)
- ->add('birthday', FormBirthdayType::class);
- $builder->addEventSubscriber(new NumberTypeByCitizenshipSubscriber());
- $builder->add('country', BaseCountryType::class, [
- 'constraints' => [
- new NotBlank([
- 'message' => 'validate.required'
- ])
- ]
- ]);
- $builder->addEventSubscriber(new CityListByCountrySubscriber());
- $builder->add('address', BaseInputType::class, [
- 'label' => 'label.address',
- 'help' => 'help.enterFullAddress',
- 'constraints' => [
- new NotBlank([
- 'message' => 'validate.required'
- ])
- ]
- ])
- ->add('personPhones', BaseCollectionsType::class, [
- 'entry_type' => PersonPhoneType::class
- ])
- ->add('personEmails', BaseCollectionsType::class, [
- 'entry_type' => PersonEmailType::class
- ])
- ;
- }
- public function configureOptions(OptionsResolver $resolver)
- {
- $resolver->setDefaults([
- 'data_class' => Person::class,
- 'citizenship' => Person::$DOMESTIC
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement