mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 21:13:57 +00:00
replace dropdown for selecting reasons and use chillEntity for reason rendering
This commit is contained in:
@@ -116,7 +116,7 @@ class ActivityType extends AbstractType
|
||||
])
|
||||
->add('reasons', TranslatableActivityReason::class, array(
|
||||
'multiple' => true,
|
||||
'required' => false
|
||||
'required' => false,
|
||||
))
|
||||
->add('type', TranslatableActivityType::class, array(
|
||||
'placeholder' => 'Choose a type',
|
||||
|
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
* Copyright (C) 2014-2020, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@@ -27,20 +27,34 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Chill\ActivityBundle\Entity\ActivityReason;
|
||||
use Chill\ActivityBundle\Templating\Entity\ActivityReasonRender;
|
||||
|
||||
/**
|
||||
* Description of TranslatableActivityReason
|
||||
*
|
||||
* @author Champs-Libres Coop
|
||||
* FormType to choose amongst activity reasons
|
||||
*
|
||||
*/
|
||||
class TranslatableActivityReason extends AbstractType
|
||||
{
|
||||
|
||||
private $translatableStringHelper;
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var ActivityReasonRender
|
||||
*/
|
||||
protected $reasonRender;
|
||||
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper)
|
||||
{
|
||||
public function __construct(
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
ActivityReasonRender $reasonRender
|
||||
) {
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->reasonRender = $reasonRender;
|
||||
}
|
||||
|
||||
public function getBlockPrefix()
|
||||
@@ -55,20 +69,20 @@ class TranslatableActivityReason extends AbstractType
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$helper = $this->translatableStringHelper;
|
||||
$resolver->setDefaults(
|
||||
array(
|
||||
'class' => 'ChillActivityBundle:ActivityReason',
|
||||
'choice_label' => function($choice, $key) use ($helper) {
|
||||
return $helper->localize($choice->getName());
|
||||
'choice_label' => function(ActivityReason $choice) {
|
||||
return $this->reasonRender->renderString($choice, []);
|
||||
},
|
||||
'group_by' => function($choice, $key) use ($helper) {
|
||||
return $helper->localize($choice->getCategory()->getName());
|
||||
'group_by' => function(ActivityReason $choice) {
|
||||
return $this->translatableStringHelper->localize($choice->getCategory()->getName());
|
||||
},
|
||||
'query_builder' => function (EntityRepository $er) {
|
||||
return $er->createQueryBuilder('r')
|
||||
->where('r.active = true');
|
||||
}
|
||||
},
|
||||
'attr' => [ 'class' => ' select2 ']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user