1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys AirBundle package.
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Rapsys\AirBundle\Form
;
14 use Doctrine\ORM\EntityManagerInterface
;
16 use Symfony\Bridge\Doctrine\Form\Type\EntityType
;
17 use Symfony\Component\Form\Extension\Core\Type\ChoiceType
;
18 use Symfony\Component\Form\Extension\Core\Type\TelType
;
19 use Symfony\Component\Form\Extension\Core\Type\TextType
;
20 use Symfony\Component\Form\FormBuilderInterface
;
21 use Symfony\Component\OptionsResolver\OptionsResolver
;
23 use Rapsys\AirBundle\Entity\Country
;
24 use Rapsys\AirBundle\Entity\Dance
;
25 use Rapsys\AirBundle\Entity\User
;
26 use Rapsys\AirBundle\Transformer\DanceTransformer
;
27 use Rapsys\AirBundle\Transformer\SubscriptionTransformer
;
29 use Rapsys\UserBundle\Form\RegisterType
as BaseRegisterType
;
34 class RegisterType
extends BaseRegisterType
{
38 * @param EntityManagerInterface $manager The entity manager
40 public function __construct(private EntityManagerInterface
$manager) {
46 public function buildForm(FormBuilderInterface
$builder, array $options): FormBuilderInterface
{
47 //Call parent build form
48 $form = parent
::buildForm($builder, $options);
50 //Add extra city field
51 if (!empty($options['city'])) {
52 $form->add('city', TextType
::class, ['attr' => ['placeholder' => 'Your city'], 'required' => false]);
55 //Add extra country field
56 if (!empty($options['country'])) {
58 $form->add('country', EntityType
::class, ['class' => $options['country_class'], 'choice_label' => 'title'/*, 'choices' => $options['location_choices']*/, 'preferred_choices' => $options['country_favorites'], 'attr' => ['placeholder' => 'Your country'], 'choice_translation_domain' => false, 'required' => true, 'data' => $options['country_default']]);
61 //Add extra dance field
62 if (!empty($options['dance'])) {
64 #$form->add('dances', EntityType::class, ['class' => $options['dance_class'], 'choice_label' => null, 'preferred_choices' => $options['dance_favorites'], 'attr' => ['placeholder' => 'Your dance'], 'choice_translation_domain' => false, 'required' => false, 'data' => $options['dance_default']]);
67 ->create('dances', ChoiceType
::class, ['attr' => ['placeholder' => 'Your dance']/*, 'by_reference' => false*/, 'choice_attr' => ['class' => 'row'], 'choice_translation_domain' => false, 'choices' => $options['dance_choices'], 'multiple' => true, 'preferred_choices' => $options['dance_favorites'], 'required' => false])
68 ->addModelTransformer(new DanceTransformer($this->manager
))
69 #->addModelTransformer(new CollectionToArrayTransformer)
71 /*, 'expanded' => true*/ /*, 'data' => $options['dance_default']*/
74 //Add extra phone field
75 if (!empty($options['phone'])) {
76 $form->add('phone', TelType
::class, ['attr' => ['placeholder' => 'Your phone'], 'required' => false]);
79 //Add extra pseudonym field
80 if (!empty($options['pseudonym'])) {
81 $form->add('pseudonym', TextType
::class, ['attr' => ['placeholder' => 'Your pseudonym'], 'required' => false]);
84 //Add extra subscription field
85 if (!empty($options['subscription'])) {
86 //Add subscription field
87 #$form->add('subscriptions', EntityType::class, ['class' => $options['subscription_class'], 'choice_label' => 'pseudonym', 'preferred_choices' => $options['subscription_favorites'], 'attr' => ['placeholder' => 'Your subscription'], 'choice_translation_domain' => false, 'required' => false, 'data' => $options['subscription_default']]);
88 #$form->add('subscriptions', ChoiceType::class, ['attr' => ['placeholder' => 'Your subscription'], 'choice_attr' => ['class' => 'row'], 'choice_translation_domain' => false, 'choices' => $options['subscription_choices'], 'multiple' => true, 'preferred_choices' => $options['subscription_favorites'], 'required' => false]);
91 //XXX: by_reference need to be false to allow persisting of data from the read only inverse side
92 ->create('subscriptions', ChoiceType
::class, ['attr' => ['placeholder' => 'Your subscription']/*, 'by_reference' => false*/, 'choice_attr' => ['class' => 'row'], 'choice_translation_domain' => false, 'choices' => $options['subscription_choices'], 'multiple' => true, 'preferred_choices' => $options['subscription_favorites'], 'required' => false])
93 ->addModelTransformer(new SubscriptionTransformer($this->manager
))
94 #->addModelTransformer(new CollectionToArrayTransformer)
96 /*, 'expanded' => true*/ /*, 'data' => $options['subscription_default']*/
99 //Add extra zipcode field
100 if (!empty($options['zipcode'])) {
101 $form->add('zipcode', TextType
::class, ['attr' => ['placeholder' => 'Your zipcode'], 'required' => false]);
111 public function configureOptions(OptionsResolver
$resolver): void {
112 //Call parent configure options
113 parent
::configureOptions($resolver);
116 $resolver->setDefaults(
120 'country_class' => 'Rapsys\AirBundle\Entity\Country',
121 'country_default' => null,
122 'country_favorites' => [],
124 'dance_choices' => [],
125 #'dance_default' => null,
126 'dance_favorites' => [],
129 'subscription' => false,
130 'subscription_choices' => [],
131 #'subscription_default' => null,
132 'subscription_favorites' => [],
137 //Add extra city option
138 $resolver->setAllowedTypes('city', 'boolean');
140 //Add extra country option
141 $resolver->setAllowedTypes('country', 'boolean');
144 $resolver->setAllowedTypes('country_class', 'string');
146 //Add country default
147 $resolver->setAllowedTypes('country_default', [Country
::class, 'null']);
149 //Add country favorites
150 $resolver->setAllowedTypes('country_favorites', 'array');
152 //Add extra dance option
153 $resolver->setAllowedTypes('dance', 'boolean');
156 $resolver->setAllowedTypes('dance_choices', 'array');
159 #$resolver->setAllowedTypes('dance_default', 'integer');
161 //Add dance favorites
162 $resolver->setAllowedTypes('dance_favorites', 'array');
164 //Add extra phone option
165 $resolver->setAllowedTypes('phone', 'boolean');
167 //Add extra pseudonym option
168 $resolver->setAllowedTypes('pseudonym', 'boolean');
170 //Add extra subscription option
171 $resolver->setAllowedTypes('subscription', 'boolean');
173 //Add subscription choices
174 $resolver->setAllowedTypes('subscription_choices', 'array');
176 //Add subscription default
177 #$resolver->setAllowedTypes('subscription_default', 'integer');
179 //Add subscription favorites
180 $resolver->setAllowedTypes('subscription_favorites', 'array');
182 //Add extra zipcode option
183 $resolver->setAllowedTypes('zipcode', 'boolean');
189 public function getName(): string {
190 return 'rapsys_air_register';