mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-02 23:16:13 +00:00
creation of CivilityPicker and attempt to implement -> still error
This commit is contained in:
parent
f2221565c5
commit
f1a9a872bb
57
src/Bundle/ChillMainBundle/Form/Type/PickCivilityType.php
Normal file
57
src/Bundle/ChillMainBundle/Form/Type/PickCivilityType.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?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\Extension\Core\Type\TextType;
|
||||||
|
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 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')
|
||||||
|
->where('c.active = true')
|
||||||
|
->orderBy('c.order');
|
||||||
|
},
|
||||||
|
)
|
||||||
|
->setDefault('placeholder', 'choose civility')
|
||||||
|
->setDefault('class', Civility::class);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getParent()
|
||||||
|
{
|
||||||
|
return Entity::class;
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,7 @@ use Chill\MainBundle\Form\Type\ChillCollectionType;
|
|||||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||||
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
||||||
use Chill\MainBundle\Form\Type\CommentType;
|
use Chill\MainBundle\Form\Type\CommentType;
|
||||||
|
use Chill\MainBundle\Form\Type\PickCivilityType;
|
||||||
use Chill\MainBundle\Form\Type\Select2CountryType;
|
use Chill\MainBundle\Form\Type\Select2CountryType;
|
||||||
use Chill\MainBundle\Form\Type\Select2LanguageType;
|
use Chill\MainBundle\Form\Type\Select2LanguageType;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
@ -190,18 +191,7 @@ class PersonType extends AbstractType
|
|||||||
|
|
||||||
if ('visible' === $this->config['civility']) {
|
if ('visible' === $this->config['civility']) {
|
||||||
$builder
|
$builder
|
||||||
->add('civility', EntityType::class, [
|
->add('civility', PickCivilityType::class, [
|
||||||
'label' => 'Civility',
|
|
||||||
'class' => Civility::class,
|
|
||||||
'choice_label' => function (Civility $civility): string {
|
|
||||||
return $this->translatableStringHelper->localize($civility->getName());
|
|
||||||
},
|
|
||||||
'query_builder' => static function (EntityRepository $er): QueryBuilder {
|
|
||||||
return $er->createQueryBuilder('c')
|
|
||||||
->where('c.active = true')
|
|
||||||
->orderBy('c.order');
|
|
||||||
},
|
|
||||||
'placeholder' => 'choose civility',
|
|
||||||
'required' => false,
|
'required' => false,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user