You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
4.2KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Form\Address;
  3. use Lc\CaracoleBundle\Model\Address\AddressInterface;
  4. use Lc\CaracoleBundle\Model\Address\AddressModel;
  5. use Lc\SovBundle\Translation\TranslatorAdmin;
  6. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  7. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  8. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use Symfony\Component\Form\AbstractType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. class AddressType extends AbstractType
  15. {
  16. protected $em;
  17. protected $translatorAdmin;
  18. public function __construct(EntityManagerInterface $entityManager, TranslatorAdmin $translatorAdmin)
  19. {
  20. $this->em = $entityManager;
  21. $this->translatorAdmin = $translatorAdmin;
  22. }
  23. public function buildForm(FormBuilderInterface $builder, array $options)
  24. {
  25. $builder
  26. ->add('title', TextType::class, ['label' => 'Titre'])
  27. ->add(
  28. 'type',
  29. ChoiceType::class,
  30. [
  31. 'label' => 'Type',
  32. 'choices' => [
  33. $this->translatorAdmin->transField(
  34. 'typeOptions.'.AddressModel::TYPE_INDIVIDUAL,
  35. 'Address'
  36. ) => AddressModel::TYPE_INDIVIDUAL,
  37. $this->translatorAdmin->transField(
  38. 'typeOptions.'.AddressModel::TYPE_LEGAL_PERSON,
  39. 'Address'
  40. ) => AddressModel::TYPE_LEGAL_PERSON,
  41. ],
  42. ]
  43. )
  44. ->add(
  45. 'civility',
  46. ChoiceType::class,
  47. [
  48. 'label' => 'Civilité',
  49. 'required' => false,
  50. 'choices' => [
  51. '--' => '',
  52. 'Femme' => 1,
  53. 'Homme' => 0,
  54. ],
  55. ]
  56. )
  57. ->add('lastname', TextType::class, ['required' => false])
  58. ->add('firstname', TextType::class, ['required' => false])
  59. ->add('zip', TextType::class)
  60. ->add('city', TextType::class)
  61. ->add('address', TextType::class)
  62. ->add(
  63. 'phone',
  64. CollectionType::class,
  65. [
  66. 'allow_add' => true,
  67. 'allow_delete' => true,
  68. 'entry_options' => [
  69. 'label' => false,
  70. ],
  71. 'required' => false,
  72. 'row_attr' => array(
  73. 'data-reindex-key' => true,
  74. 'class' => 'field-collection',
  75. ),
  76. 'attr' => array(
  77. 'class' => 'field-collection-group',
  78. ),
  79. ]
  80. )
  81. ->add('company', TextType::class, ['required' => false])
  82. ->add('siret', TextType::class, ['required' => false])
  83. ->add('tva', TextType::class, ['required' => false])
  84. ->add('country', HiddenType::class, ['data' => 'France'])
  85. ->add('status', HiddenType::class, ['data' => '1']);
  86. }
  87. public function configureOptions(OptionsResolver $resolver)
  88. {
  89. $resolver->setDefaults(
  90. [
  91. 'label' => false,
  92. 'data_class' => $this->em->getEntityName(AddressInterface::class),
  93. ]
  94. );
  95. }
  96. }