From aa02597541777022ffb67a0a3c16be10a6cbf8e5 Mon Sep 17 00:00:00 2001 From: Tchama Date: Tue, 29 Jan 2019 14:28:27 +0100 Subject: [PATCH] adapt select moderator field in new event form --- Controller/EventController.php | 24 ++++++++++++++- Form/EventType.php | 56 +++++++++++++++++++++++++--------- 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/Controller/EventController.php b/Controller/EventController.php index c0b64a5f0..3925023bb 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -1,5 +1,25 @@ , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + namespace Chill\EventBundle\Controller; use Chill\EventBundle\Entity\Participation; @@ -105,7 +125,9 @@ class EventController extends Controller { $form = $this->createForm(EventType::class, $entity, array( 'action' => $this->generateUrl('chill_event__event_create'), - 'method' => 'POST' + 'method' => 'POST', + 'center' => $entity->getCenter(), + 'role' => new Role('CHILL_EVENT_CREATE') )); $form->add('submit', SubmitType::class, array('label' => 'Create')); diff --git a/Form/EventType.php b/Form/EventType.php index d7e4d4d65..645461e8d 100644 --- a/Form/EventType.php +++ b/Form/EventType.php @@ -1,21 +1,42 @@ , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + namespace Chill\EventBundle\Form; -use Chill\MainBundle\Form\Type\ChillDateTimeType; -use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Chill\EventBundle\Form\Type\PickEventType; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; -use Chill\MainBundle\Security\Authorization\AuthorizationHelper; -use Doctrine\Common\Persistence\ObjectManager; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\MainBundle\Entity\User; -use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Scope; - +use Chill\MainBundle\Form\Type\ChillDateTimeType; +use Chill\MainBundle\Form\Type\UserPickerType; +use Chill\MainBundle\Security\Authorization\AuthorizationHelper; +use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\ORM\EntityRepository; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Role\Role; class EventType extends AbstractType @@ -76,6 +97,7 @@ class EventType extends AbstractType 'class' => Center::class, 'choices' => $userReachableCenters, 'attr' => array('class' => 'select2 chill-category-link-parent'), + 'disabled' => true, 'choice_attr' => function (Center $center) { return array( 'class' => ' chill-category-link-parent', @@ -103,22 +125,26 @@ class EventType extends AbstractType }, )) ->add('type', PickEventType::class) - ->add('moderator', EntityType::class, array( - 'class' => User::class, - 'required' => false, - 'placeholder' => '' + ->add('moderator', UserPickerType::class, array( + 'center' => $options['center'], + 'role' => $options['role'] )) ; } /** - * @param OptionsResolverInterface $resolver + * @param OptionsResolver $resolver */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'Chill\EventBundle\Entity\Event' )); + $resolver + ->setRequired(array('center', 'role')) + ->setAllowedTypes('center', Center::class) + ->setAllowedTypes('role', Role::class) + ; } /**