mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 11:33:49 +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:
@@ -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 '],
|
||||
]
|
||||
);
|
Reference in New Issue
Block a user