mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-28 21:16:13 +00:00
Fixed: Fixed loading the list of activity reason category, in dedicated type
fix https://gitlab.com/Chill-Projet/chill-bundles/-/issues/35
This commit is contained in:
parent
08ddbee6af
commit
e99fb75ebd
@ -1,59 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Chill is a software for social workers
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view
|
|
||||||
* the LICENSE file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Chill\ActivityBundle\Form\Type;
|
|
||||||
|
|
||||||
use Doctrine\ORM\EntityRepository;
|
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
|
||||||
use Symfony\Component\Form\AbstractType;
|
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Description of TranslatableActivityReasonCategory.
|
|
||||||
*/
|
|
||||||
class TranslatableActivityReasonCategory extends AbstractType
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var RequestStack
|
|
||||||
*/
|
|
||||||
private $requestStack;
|
|
||||||
|
|
||||||
public function __construct(RequestStack $requestStack)
|
|
||||||
{
|
|
||||||
$this->requestStack = $requestStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver)
|
|
||||||
{
|
|
||||||
$locale = $this->requestStack->getCurrentRequest()->getLocale();
|
|
||||||
$resolver->setDefaults(
|
|
||||||
[
|
|
||||||
'class' => 'ChillActivityBundle:ActivityReasonCategory',
|
|
||||||
'choice_label' => 'name[' . $locale . ']',
|
|
||||||
'query_builder' => static function (EntityRepository $er) {
|
|
||||||
return $er->createQueryBuilder('c')
|
|
||||||
->where('c.active = true');
|
|
||||||
},
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getBlockPrefix()
|
|
||||||
{
|
|
||||||
return 'translatable_activity_reason_category';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getParent()
|
|
||||||
{
|
|
||||||
return EntityType::class;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\ActivityBundle\Form\Type;
|
||||||
|
|
||||||
|
use Chill\ActivityBundle\Entity\ActivityReasonCategory;
|
||||||
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of TranslatableActivityReasonCategory.
|
||||||
|
*/
|
||||||
|
class TranslatableActivityReasonCategoryType extends AbstractType
|
||||||
|
{
|
||||||
|
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||||
|
|
||||||
|
private TranslatorInterface $translator;
|
||||||
|
|
||||||
|
public function __construct(TranslatableStringHelperInterface $translatableStringHelper, TranslatorInterface $translator)
|
||||||
|
{
|
||||||
|
$this->translatableStringHelper = $translatableStringHelper;
|
||||||
|
$this->translator = $translator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
{
|
||||||
|
$resolver->setDefaults(
|
||||||
|
[
|
||||||
|
'class' => ActivityReasonCategory::class,
|
||||||
|
'choice_label' => function (ActivityReasonCategory $category) {
|
||||||
|
return $this->translatableStringHelper->localize($category->getName())
|
||||||
|
. (!$category->getActive() ? ' (' . $this->translator->trans('inactive') . ')' : '');
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockPrefix()
|
||||||
|
{
|
||||||
|
return 'translatable_activity_reason_category';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getParent()
|
||||||
|
{
|
||||||
|
return EntityType::class;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user