mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
creation of CivilityPicker and attempt to implement -> still error
This commit is contained in:
70
src/Bundle/ChillMainBundle/Form/Type/PickCivilityType.php
Normal file
70
src/Bundle/ChillMainBundle/Form/Type/PickCivilityType.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Form\Type;
|
||||
|
||||
use Chill\MainBundle\Entity\Civility;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\Mapping\Entity;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class PickCivilityType extends AbstractType
|
||||
{
|
||||
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper)
|
||||
{
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
/** @var QueryBuilder $qb */
|
||||
$qb = $options['query_builder'];
|
||||
|
||||
$qb->where($qb->expr()->eq('at.active', ':active'))
|
||||
->orderBy('c.order');
|
||||
$qb->setParameter('active', true);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefault('label', 'Civility')
|
||||
->setDefault('choice_label', function (Civility $civility): string {
|
||||
return $this->translatableStringHelper->localize($civility->getName());
|
||||
}
|
||||
)
|
||||
->setDefault('query_builder', function (EntityRepository $er): QueryBuilder
|
||||
{
|
||||
return $er->createQueryBuilder('c');
|
||||
},
|
||||
)
|
||||
->setDefault('placeholder', 'choose civility')
|
||||
->setDefault('class', Civility::class);
|
||||
|
||||
}
|
||||
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'civility_type';
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return Entity::class;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user