diff --git a/src/Bundle/ChillMainBundle/Form/Type/CenterType.php b/src/Bundle/ChillMainBundle/Form/Type/CenterType.php index ba039c938..0366e8ccf 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/CenterType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/CenterType.php @@ -95,9 +95,12 @@ class CenterType extends AbstractType public function configureOptions(OptionsResolver $resolver) { if (count($this->reachableCenters) > 1) { - $resolver->setDefault('class', Center::class); - $resolver->setDefault('choices', $this->reachableCenters); + $resolver->setDefault('class', Center::class) + ->setDefault('choices', $this->reachableCenters) + ->setDefault('placeholder', 'Pick a center') + ; } + } /** diff --git a/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverDispatcher.php b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverDispatcher.php new file mode 100644 index 000000000..6b1f2a897 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverDispatcher.php @@ -0,0 +1,34 @@ +resolvers = $resolvers; + } + + /** + * @param mixed $entity + * @param array|null $options + * @return null|Center|Center[] + */ + public function resolveCenter($entity, ?array $options = []) + { + foreach($this->resolvers as $priority => $resolver) { + if ($resolver->supports($entity, $options)) { + return $resolver->resolveCenter($entity, $options); + } + } + + return null; + } +} diff --git a/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverInterface.php b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverInterface.php new file mode 100644 index 000000000..db49874b7 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Security/Resolver/CenterResolverInterface.php @@ -0,0 +1,19 @@ +getCenter(); + } + + public static function getDefaultPriority(): int + { + return -256; + } +} diff --git a/src/Bundle/ChillMainBundle/Security/Resolver/ResolverTwigExtension.php b/src/Bundle/ChillMainBundle/Security/Resolver/ResolverTwigExtension.php new file mode 100644 index 000000000..21ece21a3 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Security/Resolver/ResolverTwigExtension.php @@ -0,0 +1,36 @@ +centerResolverDispatcher = $centerResolverDispatcher; + } + + public function getFilters() + { + return [ + new TwigFilter('chill_resolve_center', [$this, 'resolveCenter']) + ]; + } + + /** + * @param mixed $entity + * @param array|null $options + * @return Center|Center[]|null + */ + public function resolveCenter($entity, ?array $options = []) + { + return $this->centerResolverDispatcher->resolveCenter($entity, $options); + } + +} diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index b230b6ac1..59dcd8c73 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -177,6 +177,7 @@ Exports list: Liste des exports Create an export: Créer un export #export creation step 'center' : pick a center Pick centers: Choisir les centres +Pick a center: Choisir un centre The export will contains only data from the picked centers.: L'export ne contiendra que les données des centres choisis. This will eventually restrict your possibilities in filtering the data.: Les possibilités de filtrages seront adaptées aux droits de consultation pour les centres choisis. Go to export options: Vers la préparation de l'export diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonController.php b/src/Bundle/ChillPersonBundle/Controller/PersonController.php index 759f892b2..03da97d5f 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonController.php @@ -230,13 +230,16 @@ final class PersonController extends AbstractController */ public function newAction(Request $request) { - $defaultCenter = $this->security - ->getUser() - ->getGroupCenters()[0] - ->getCenter(); + $person = new Person(); - $person = (new Person(new \DateTime('now'))) - ->setCenter($defaultCenter); + if (1 === count($this->security->getUser() + ->getGroupCenters())) { + $person->setCenter( + $this->security->getUser() + ->getGroupCenters()[0] + ->getCenter() + ); + } $form = $this->createForm(CreationPersonType::class, $person, [ 'validation_groups' => ['create'] diff --git a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php index 32b7a69f2..36d088c25 100644 --- a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php @@ -21,7 +21,9 @@ namespace Chill\PersonBundle\Form; +use Chill\MainBundle\Form\Event\CustomizeFormEvent; use Chill\PersonBundle\Entity\Person; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -33,6 +35,7 @@ use Chill\PersonBundle\Form\Type\GenderType; use Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer; use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper; use Chill\PersonBundle\Form\Type\PersonAltNameType; +use Chill\MainBundle\Form\Type\Export\PickCenterType; final class CreationPersonType extends AbstractType { @@ -40,10 +43,6 @@ final class CreationPersonType extends AbstractType // TODO: See if this is still valid and update accordingly. const NAME = 'chill_personbundle_person_creation'; - const FORM_NOT_REVIEWED = 'not_reviewed'; - const FORM_REVIEWED = 'reviewed' ; - const FORM_BEING_REVIEWED = 'being_reviewed'; - /** * * @var CenterTransformer @@ -56,12 +55,16 @@ final class CreationPersonType extends AbstractType */ protected $configPersonAltNamesHelper; + private EventDispatcherInterface $dispatcher; + public function __construct( CenterTransformer $centerTransformer, - ConfigPersonAltNamesHelper $configPersonAltNamesHelper + ConfigPersonAltNamesHelper $configPersonAltNamesHelper, + EventDispatcherInterface $dispatcher ) { $this->centerTransformer = $centerTransformer; $this->configPersonAltNamesHelper = $configPersonAltNamesHelper; + $this->dispatcher = $dispatcher; } /** @@ -79,7 +82,9 @@ final class CreationPersonType extends AbstractType ->add('gender', GenderType::class, array( 'required' => true, 'placeholder' => null )) - ->add('center', CenterType::class) + ->add('center', CenterType::class, [ + 'required' => false + ]) ; if ($this->configPersonAltNamesHelper->hasAltNames()) { @@ -87,6 +92,11 @@ final class CreationPersonType extends AbstractType 'by_reference' => false ]); } + + $this->dispatcher->dispatch( + new CustomizeFormEvent(static::class, $builder), + CustomizeFormEvent::NAME + ); } /** diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index f60b7dc9e..612a5609c 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -146,10 +146,10 @@ {% endif %} {% endif %} - {% if options['addCenter'] %} + {% if options['addCenter'] and person|chill_resolve_center is not null %}