]> Raphaël G. Git Repositories - airbundle/blobdiff - Form/CalendarType.php
Enable contact captcha
[airbundle] / Form / CalendarType.php
index be5fcab53198b1bbcef6b04eef43090939c22d1f..8b15b010f21dbe015233cddc82a67acfc4bb6241 100644 (file)
@@ -1,41 +1,55 @@
-<?php
+<?php declare(strict_types=1);
+
+/*
+ * This file is part of the Rapsys AirBundle package.
+ *
+ * (c) Raphaël Gertz <symfony@rapsys.eu>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
 
 namespace Rapsys\AirBundle\Form;
 
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\FormBuilderInterface;
 use Symfony\Component\OptionsResolver\OptionsResolver;
-use Symfony\Component\Form\Extension\Core\Type\TextType;
+use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
-use Symfony\Component\Validator\Constraints\NotBlank;
 
 class CalendarType extends AbstractType {
        /**
         * {@inheritdoc}
         */
-       public function buildForm(FormBuilderInterface $builder, array $options) {
-               return $builder
-                       ->add('calendar', TextType::class, ['label' => 'Calendar id', 'attr' => ['placeholder' => 'Your calendar id'], 'constraints' => [new NotBlank(['message' => 'Please provide your calendar id'])]])
-                       //TODO: validate prefix against [a-v0-9]{5,}
-                       //XXX: see https://developers.google.com/calendar/api/v3/reference/events/insert#id
-                       ->add('prefix', TextType::class, ['label' => 'Prefix', 'attr' => ['placeholder' => 'Your prefix'], 'constraints' => [new NotBlank(['message' => 'Please provide your prefix'])]])
-                       ->add('project', TextType::class, ['label' => 'Project id', 'attr' => ['placeholder' => 'Your project id'], 'required' => false])
-                       ->add('client', TextType::class, ['label' => 'Client id', 'attr' => ['placeholder' => 'Your client id'], 'required' => false])
-                       ->add('secret', TextType::class, ['label' => 'Client secret', 'attr' => ['placeholder' => 'Your client secret'], 'required' => false])
-                       ->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
+       public function buildForm(FormBuilderInterface $builder, array $options): void {
+               //Build form
+               $builder
+                       ->add('calendar', ChoiceType::class, ['attr' => ['placeholder' => 'Your calendar'], 'choice_translation_domain' => false, 'expanded' => true, 'multiple' => true, 'choices' => $options['calendar_choices']/*, 'data' => $options['calendar_default']*/, 'choice_attr' => ['class' => 'row']])
+                       ->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']])
+                       ->add('refresh', SubmitType::class, ['label' => 'Refresh', 'attr' => ['class' => 'submit']])
+                       ->add('add', SubmitType::class, ['label' => 'Add', 'attr' => ['class' => 'submit']])
+                       ->add('delete', SubmitType::class, ['label' => 'Delete', 'attr' => ['class' => 'submit']])
+                       ->add('unlink', SubmitType::class, ['label' => 'Unlink', 'attr' => ['class' => 'submit']]);
        }
 
        /**
         * {@inheritdoc}
         */
-       public function configureOptions(OptionsResolver $resolver) {
-               $resolver->setDefaults(['error_bubbling' => true]);
+       public function configureOptions(OptionsResolver $resolver): void {
+               //Set defaults
+               $resolver->setDefaults(['error_bubbling' => true, 'calendar_choices' => [], /*'calendar_default' => ['primary']*/]);
+
+               //Add calendar choices
+               $resolver->setAllowedTypes('calendar_choices', 'array');
+
+               //Add calendar default
+               #$resolver->setAllowedTypes('calendar_default', 'integer');
        }
 
        /**
         * {@inheritdoc}
         */
-       public function getName() {
+       public function getName(): string {
                return 'calendar_form';
        }
 }