Advertisement
SentinelBL

PersonFormTye

Dec 18th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Form\EntityType;
  4.  
  5. use App\Entity\Person;
  6.  
  7. use App\EventSubscriber\NumberTypeByCitizenshipSubscriber;
  8. use App\EventSubscriber\CityListByCountrySubscriber;
  9. use App\Form\AdminType\AdminAvailabilityType;
  10. use App\Form\AdminType\AdminCreatedAtType;
  11. use App\Form\AdminType\AdminCreatedByType;
  12. use App\Form\AdminType\AdminUpdatedAtType;
  13. use App\Form\AdminType\AdminUpdatedByType;
  14. use App\Form\AdminType\AdminVisibilityType;
  15. use App\Form\BaseType\BaseCitizenshipType;
  16. use App\Form\BaseType\BaseCollectionsType;
  17. use App\Form\BaseType\BaseCountryType;
  18. use App\Form\BaseType\BaseInputType;
  19. use App\Form\FormType\FormBirthdayType;
  20. use App\Form\FormType\FormGenderType;
  21. use App\Form\FormType\FormNameType;
  22. use Symfony\Component\Form\AbstractType;
  23. use Symfony\Component\Form\FormBuilderInterface;
  24. use Symfony\Component\OptionsResolver\OptionsResolver;
  25. use Symfony\Component\Validator\Constraints\NotBlank;
  26.  
  27. /**
  28. * Defines the form used to create or update Person entity.
  29. */
  30. class PersonType extends AbstractType
  31. {
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function buildForm(FormBuilderInterface $builder, array $options)
  36. {
  37.  
  38. /** @var Person|null $person */
  39. $builder
  40. ->add('hidden', AdminVisibilityType::class)
  41. ->add('locked', AdminAvailabilityType::class)
  42. ->add('createdBy', AdminCreatedByType::class)
  43. ->add('updatedBy', AdminUpdatedByType::class)
  44. ->add('createdAt', AdminCreatedAtType::class)
  45. ->add('updatedAt', AdminUpdatedAtType::class)
  46. ->add('firstName', FormNameType::class, [
  47. 'label' => 'label.firstName',
  48. ])
  49. ->add('middleName', FormNameType::class, [
  50. 'label' => 'label.middleName'
  51. ])
  52. ->add('lastName', FormNameType::class, [
  53. 'label' => 'label.lastName'
  54. ])
  55. ->add('gender', FormGenderType::class)
  56. ->add('citizenship', BaseCitizenshipType::class)
  57. ->add('birthday', FormBirthdayType::class);
  58. $builder->addEventSubscriber(new NumberTypeByCitizenshipSubscriber());
  59. $builder->add('country', BaseCountryType::class, [
  60. 'constraints' => [
  61. new NotBlank([
  62. 'message' => 'validate.required'
  63. ])
  64. ]
  65. ]);
  66. $builder->addEventSubscriber(new CityListByCountrySubscriber());
  67. $builder->add('address', BaseInputType::class, [
  68. 'label' => 'label.address',
  69. 'help' => 'help.enterFullAddress',
  70. 'constraints' => [
  71. new NotBlank([
  72. 'message' => 'validate.required'
  73. ])
  74. ]
  75. ])
  76. ->add('personPhones', BaseCollectionsType::class, [
  77. 'entry_type' => PersonPhoneType::class
  78. ])
  79. ->add('personEmails', BaseCollectionsType::class, [
  80. 'entry_type' => PersonEmailType::class
  81. ])
  82. ;
  83. }
  84.  
  85. public function configureOptions(OptionsResolver $resolver)
  86. {
  87. $resolver->setDefaults([
  88. 'data_class' => Person::class,
  89. 'citizenship' => Person::$DOMESTIC
  90. ]);
  91. }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement