mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-10-31 17:28:23 +00:00 
			
		
		
		
	Fixed: [Activity] fix appearance of reason list in Activity form
Fix https://gitlab.com/Chill-Projet/chill-bundles/-/issues/44
This commit is contained in:
		| @@ -43,6 +43,7 @@ use Symfony\Component\HttpFoundation\Request; | ||||
| use Symfony\Component\HttpFoundation\Response; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Symfony\Component\Serializer\SerializerInterface; | ||||
| use Symfony\Contracts\Translation\TranslatorInterface; | ||||
| use function array_key_exists; | ||||
|  | ||||
| final class ActivityController extends AbstractController | ||||
| @@ -73,6 +74,8 @@ final class ActivityController extends AbstractController | ||||
|  | ||||
|     private ThirdPartyRepository $thirdPartyRepository; | ||||
|  | ||||
|     private TranslatorInterface $translator; | ||||
|  | ||||
|     private UserRepositoryInterface $userRepository; | ||||
|  | ||||
|     public function __construct( | ||||
| @@ -89,7 +92,8 @@ final class ActivityController extends AbstractController | ||||
|         LoggerInterface $logger, | ||||
|         SerializerInterface $serializer, | ||||
|         UserRepositoryInterface $userRepository, | ||||
|         CenterResolverManagerInterface $centerResolver | ||||
|         CenterResolverManagerInterface $centerResolver, | ||||
|         TranslatorInterface $translator | ||||
|     ) { | ||||
|         $this->activityACLAwareRepository = $activityACLAwareRepository; | ||||
|         $this->activityTypeRepository = $activityTypeRepository; | ||||
| @@ -105,6 +109,7 @@ final class ActivityController extends AbstractController | ||||
|         $this->serializer = $serializer; | ||||
|         $this->userRepository = $userRepository; | ||||
|         $this->centerResolver = $centerResolver; | ||||
|         $this->translator = $translator; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -160,7 +165,7 @@ final class ActivityController extends AbstractController | ||||
|                 $this->entityManager->remove($activity); | ||||
|                 $this->entityManager->flush(); | ||||
|  | ||||
|                 $this->addFlash('success', $this->get('translator') | ||||
|                 $this->addFlash('success', $this->translator | ||||
|                     ->trans('The activity has been successfully removed.')); | ||||
|  | ||||
|                 $params = $this->buildParamsToUrl($person, $accompanyingPeriod); | ||||
| @@ -245,7 +250,7 @@ final class ActivityController extends AbstractController | ||||
|                 ); | ||||
|             } | ||||
|  | ||||
|             $this->addFlash('success', $this->get('translator')->trans('Success : activity updated!')); | ||||
|             $this->addFlash('success', $this->translator->trans('Success : activity updated!')); | ||||
|  | ||||
|             return $this->redirectToRoute('chill_activity_activity_show', $params); | ||||
|         } | ||||
| @@ -473,7 +478,7 @@ final class ActivityController extends AbstractController | ||||
|                 ); | ||||
|             } | ||||
|  | ||||
|             $this->addFlash('success', $this->get('translator')->trans('Success : activity created!')); | ||||
|             $this->addFlash('success', $this->translator->trans('Success : activity created!')); | ||||
|  | ||||
|             $params = $this->buildParamsToUrl($person, $accompanyingPeriod); | ||||
|  | ||||
|   | ||||
| @@ -13,7 +13,7 @@ namespace Chill\ActivityBundle\Form; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\Activity; | ||||
| use Chill\ActivityBundle\Entity\ActivityPresence; | ||||
| use Chill\ActivityBundle\Entity\ActivityReason; | ||||
| use Chill\ActivityBundle\Form\Type\PickActivityReasonType; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityVoter; | ||||
| use Chill\DocStoreBundle\Form\StoredObjectType; | ||||
| use Chill\MainBundle\Entity\Center; | ||||
| @@ -229,19 +229,10 @@ class ActivityType extends AbstractType | ||||
|         } | ||||
|  | ||||
|         if ($activityType->isVisible('reasons')) { | ||||
|             $builder->add('reasons', EntityType::class, [ | ||||
|             $builder->add('reasons', PickActivityReasonType::class, [ | ||||
|                 'label' => $activityType->getLabel('reasons'), | ||||
|                 'required' => $activityType->isRequired('reasons'), | ||||
|                 'class' => ActivityReason::class, | ||||
|                 'multiple' => true, | ||||
|                 'choice_label' => function (ActivityReason $activityReason) { | ||||
|                     return $this->translatableStringHelper->localize($activityReason->getName()); | ||||
|                 }, | ||||
|                 'attr' => ['class' => 'select2 '], | ||||
|                 'query_builder' => static function (EntityRepository $er) { | ||||
|                     return $er->createQueryBuilder('a') | ||||
|                         ->where('a.active = true'); | ||||
|                 }, | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -12,9 +12,9 @@ declare(strict_types=1); | ||||
| namespace Chill\ActivityBundle\Form\Type; | ||||
| 
 | ||||
| use Chill\ActivityBundle\Entity\ActivityReason; | ||||
| use Chill\ActivityBundle\Repository\ActivityReasonRepository; | ||||
| use Chill\ActivityBundle\Templating\Entity\ActivityReasonRender; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelperInterface; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Symfony\Component\Form\AbstractType; | ||||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
| @@ -22,31 +22,29 @@ use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
| /** | ||||
|  * FormType to choose amongst activity reasons. | ||||
|  */ | ||||
| class TranslatableActivityReason extends AbstractType | ||||
| class PickActivityReasonType extends AbstractType | ||||
| { | ||||
|     /** | ||||
|      * @var ActivityReasonRender | ||||
|      */ | ||||
|     protected $reasonRender; | ||||
|     private ActivityReasonRepository $activityReasonRepository; | ||||
| 
 | ||||
|     /** | ||||
|      * @var TranslatableStringHelper | ||||
|      */ | ||||
|     protected $translatableStringHelper; | ||||
|     private ActivityReasonRender $reasonRender; | ||||
| 
 | ||||
|     private TranslatableStringHelperInterface $translatableStringHelper; | ||||
| 
 | ||||
|     public function __construct( | ||||
|         TranslatableStringHelper $translatableStringHelper, | ||||
|         ActivityReasonRender $reasonRender | ||||
|         ActivityReasonRepository $activityReasonRepository, | ||||
|         ActivityReasonRender $reasonRender, | ||||
|         TranslatableStringHelperInterface $translatableStringHelper | ||||
|     ) { | ||||
|         $this->translatableStringHelper = $translatableStringHelper; | ||||
|         $this->activityReasonRepository = $activityReasonRepository; | ||||
|         $this->reasonRender = $reasonRender; | ||||
|         $this->translatableStringHelper = $translatableStringHelper; | ||||
|     } | ||||
| 
 | ||||
|     public function configureOptions(OptionsResolver $resolver) | ||||
|     { | ||||
|         $resolver->setDefaults( | ||||
|             [ | ||||
|                 'class' => 'ChillActivityBundle:ActivityReason', | ||||
|                 'class' => ActivityReason::class, | ||||
|                 'choice_label' => function (ActivityReason $choice) { | ||||
|                     return $this->reasonRender->renderString($choice, []); | ||||
|                 }, | ||||
| @@ -57,10 +55,7 @@ class TranslatableActivityReason extends AbstractType | ||||
| 
 | ||||
|                     return null; | ||||
|                 }, | ||||
|                 'query_builder' => static function (EntityRepository $er) { | ||||
|                     return $er->createQueryBuilder('r') | ||||
|                         ->where('r.active = true'); | ||||
|                 }, | ||||
|                 'choices' => $this->activityReasonRepository->findAll(), | ||||
|                 'attr' => ['class' => ' select2 '], | ||||
|             ] | ||||
|         ); | ||||
| @@ -11,7 +11,7 @@ declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Tests\Form\Type; | ||||
|  | ||||
| use Chill\ActivityBundle\Form\Type\TranslatableActivityReason; | ||||
| use Chill\ActivityBundle\Form\Type\PickActivityReasonType; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Symfony\Component\Form\PreloadedExtension; | ||||
| use Symfony\Component\Form\Test\TypeTestCase; | ||||
| @@ -36,7 +36,7 @@ final class TranslatableActivityReasonTest extends TypeTestCase | ||||
|  | ||||
|     public function testSimple() | ||||
|     { | ||||
|         $translatableActivityReasonType = new TranslatableActivityReason( | ||||
|         $translatableActivityReasonType = new PickActivityReasonType( | ||||
|             $this->getTranslatableStringHelper() | ||||
|         ); | ||||
|  | ||||
|   | ||||
| @@ -4,13 +4,9 @@ services: | ||||
|         autowire: true | ||||
|         autoconfigure: true | ||||
|  | ||||
|     chill.activity.form.type.translatableactivityreason: | ||||
|         class: Chill\ActivityBundle\Form\Type\TranslatableActivityReason | ||||
|         arguments: | ||||
|             $translatableStringHelper: "@chill.main.helper.translatable_string" | ||||
|             $reasonRender: '@Chill\ActivityBundle\Templating\Entity\ActivityReasonRender' | ||||
|         tags: | ||||
|             - { name: form.type, alias: translatable_activity_reason } | ||||
|     Chill\ActivityBundle\Form\Type\PickActivityReasonType: | ||||
|         autowire: true | ||||
|         autoconfigure: true | ||||
|  | ||||
|     chill.activity.form.type.translatableactivitytype: | ||||
|         class: Chill\ActivityBundle\Form\Type\TranslatableActivityType | ||||
|   | ||||
		Reference in New Issue
	
	Block a user