From: Raphaël Gertz Date: Thu, 29 Feb 2024 16:55:25 +0000 (+0100) Subject: Update fields to choose calendar X-Git-Tag: 0.4.0~65 X-Git-Url: https://git.rapsys.eu/airbundle/commitdiff_plain/b9f1b602aea82b408825e3ea0896acf6aa856b76?ds=sidebyside Update fields to choose calendar Add refresh, add, delete and unlink submit buttons Strict types --- diff --git a/Form/CalendarType.php b/Form/CalendarType.php index be5fcab..8b15b01 100644 --- a/Form/CalendarType.php +++ b/Form/CalendarType.php @@ -1,41 +1,55 @@ - + * + * 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'; } }