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