mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Change PickGenderType form field to use in Person creation form
This commit is contained in:
parent
b78f0980f5
commit
67a6eb17db
@ -3,6 +3,7 @@
|
||||
namespace Chill\MainBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Entity\Gender;
|
||||
use Chill\MainBundle\Entity\GenderEnum;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
@ -20,11 +21,11 @@ class GenderType extends AbstractType
|
||||
'required' => true,
|
||||
])
|
||||
->add('icon', TextType::class)
|
||||
->add('isGrammatical', ChoiceType::class, [
|
||||
'choices' => [
|
||||
'Grammatical' => true,
|
||||
'Not grammatical' => false,
|
||||
],
|
||||
->add('genderTranslation', ChoiceType::class, [
|
||||
'choices' => GenderEnum::cases(),
|
||||
'choice_label' => fn(GenderEnum $enum) => ucfirst(strtolower($enum->name)),
|
||||
'choice_value' => fn(?GenderEnum $enum) => $enum ? $enum->value : null,
|
||||
'data_class' => null,
|
||||
])
|
||||
->add('active', ChoiceType::class, [
|
||||
'choices' => [
|
||||
|
@ -6,7 +6,7 @@
|
||||
<th>id</th>
|
||||
<th>{{ 'gender.label'|trans }}</th>
|
||||
<th>{{ 'gender.icon'|trans }}</th>
|
||||
<th>{{ 'gender.isGrammatical'|trans }}</th>
|
||||
<th>{{ 'gender.genderTranslation'|trans }}</th>
|
||||
<th>{{ 'gender.active'|trans }}</th>
|
||||
<th>{{ 'gender.ordering'|trans }}</th>
|
||||
<th></th>
|
||||
@ -16,15 +16,8 @@
|
||||
<tr>
|
||||
<td>{{ entity.id }}</td>
|
||||
<td>{{ entity.label|localize_translatable_string }}</td>
|
||||
{# todo: decide which icon source to use#}
|
||||
<td><i class="{{ entity.icon }}"></i></td>
|
||||
<td style="text-align:center;">
|
||||
{%- if entity.isGrammatical -%}
|
||||
<i class="fa fa-check-square-o"></i>
|
||||
{%- else -%}
|
||||
<i class="fa fa-square-o"></i>
|
||||
{%- endif -%}
|
||||
</td>
|
||||
<td>{{ entity.genderTranslation.value }}</td>
|
||||
<td style="text-align:center;">
|
||||
{%- if entity.active -%}
|
||||
<i class="fa fa-check-square-o"></i>
|
||||
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20240925133053 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add gender entity';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('CREATE SEQUENCE chill_main_gender_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
|
||||
$this->addSql('CREATE TABLE chill_main_gender (id INT NOT NULL, label JSON NOT NULL, active BOOLEAN NOT NULL, isGrammatical BOOLEAN NOT NULL, icon VARCHAR(255) NOT NULL, ordering DOUBLE PRECISION DEFAULT \'0.0\', PRIMARY KEY(id))');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP SEQUENCE chill_main_gender_id_seq CASCADE');
|
||||
$this->addSql('DROP TABLE chill_main_gender');
|
||||
}
|
||||
}
|
@ -996,7 +996,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
||||
return $this->fullnameCanonical;
|
||||
}
|
||||
|
||||
public function getGender(): ?string
|
||||
public function getGender(): ?Gender
|
||||
{
|
||||
return $this->gender;
|
||||
}
|
||||
@ -1525,7 +1525,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setGender(?string $gender): self
|
||||
public function setGender(?Gender $gender): self
|
||||
{
|
||||
$this->gender = $gender;
|
||||
|
||||
@ -1650,16 +1650,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getGenderKind(): ?Gender
|
||||
{
|
||||
return $this->genderKind;
|
||||
}
|
||||
|
||||
public function setGenderKind(?Gender $genderKind): void
|
||||
{
|
||||
$this->genderKind = $genderKind;
|
||||
}
|
||||
|
||||
private function getCurrentCenterHistory(): ?PersonCenterHistory
|
||||
{
|
||||
if (0 === $this->centerHistory->count()) {
|
||||
|
@ -20,8 +20,8 @@ use Chill\MainBundle\Form\Type\PickCenterType;
|
||||
use Chill\MainBundle\Form\Type\PickCivilityType;
|
||||
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Form\Type\GenderType;
|
||||
use Chill\PersonBundle\Form\Type\PersonAltNameType;
|
||||
use Chill\PersonBundle\Form\Type\PickGenderType;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use libphonenumber\PhoneNumberType;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
@ -60,7 +60,7 @@ final class CreationPersonType extends AbstractType
|
||||
'label' => 'Civility',
|
||||
'placeholder' => 'choose civility',
|
||||
])
|
||||
->add('gender', GenderType::class, [
|
||||
->add('gender', PickGenderType::class, [
|
||||
'required' => true, 'placeholder' => null,
|
||||
])
|
||||
->add('birthdate', ChillDateType::class, [
|
||||
|
@ -24,9 +24,9 @@ use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\PersonPhone;
|
||||
use Chill\PersonBundle\Form\Type\GenderType;
|
||||
use Chill\PersonBundle\Form\Type\PersonAltNameType;
|
||||
use Chill\PersonBundle\Form\Type\PersonPhoneType;
|
||||
use Chill\PersonBundle\Form\Type\PickGenderType;
|
||||
use Chill\PersonBundle\Form\Type\Select2MaritalStatusType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
@ -80,7 +80,7 @@ class PersonType extends AbstractType
|
||||
'input' => 'datetime_immutable',
|
||||
'widget' => 'single_text',
|
||||
])
|
||||
->add('gender', GenderType::class, [
|
||||
->add('gender', PickGenderType::class, [
|
||||
'required' => true,
|
||||
])
|
||||
->add('genderComment', CommentType::class, [
|
||||
|
@ -1,44 +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\PersonBundle\Form\Type;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* A type to select the civil union state.
|
||||
*/
|
||||
class GenderType extends AbstractType
|
||||
{
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$a = [
|
||||
Person::MALE_GENDER => Person::MALE_GENDER,
|
||||
Person::FEMALE_GENDER => Person::FEMALE_GENDER,
|
||||
Person::BOTH_GENDER => Person::BOTH_GENDER,
|
||||
];
|
||||
|
||||
$resolver->setDefaults([
|
||||
'choices' => $a,
|
||||
'expanded' => true,
|
||||
'multiple' => false,
|
||||
'placeholder' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return ChoiceType::class;
|
||||
}
|
||||
}
|
53
src/Bundle/ChillPersonBundle/Form/Type/PickGenderType.php
Normal file
53
src/Bundle/ChillPersonBundle/Form/Type/PickGenderType.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?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\PersonBundle\Form\Type;
|
||||
|
||||
use Chill\MainBundle\Entity\Gender;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* A type to select the civil union state.
|
||||
*/
|
||||
class PickGenderType extends AbstractType
|
||||
{
|
||||
public function __construct(private readonly TranslatableStringHelper $translatableStringHelper) {}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefault('label', 'Gender')
|
||||
->setDefault(
|
||||
'choice_label',
|
||||
fn (Gender $gender): string => $this->translatableStringHelper->localize($gender->getLabel())
|
||||
)
|
||||
->setDefault(
|
||||
'query_builder',
|
||||
static fn (EntityRepository $er): QueryBuilder => $er->createQueryBuilder('g')
|
||||
->where('g.active = true')
|
||||
->orderBy('g.order'),
|
||||
)
|
||||
->setDefault('placeholder', 'choose gender')
|
||||
->setDefault('class', Gender::class);
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return EntityType::class;
|
||||
}
|
||||
}
|
@ -106,7 +106,7 @@
|
||||
{%- endif -%}
|
||||
{%- elseif person.birthdate is not null -%}
|
||||
<time datetime="{{ person.birthdate|date('Y-m-d') }}" title="{{ 'Birthdate'|trans }}">
|
||||
{{ 'Born the date'|trans({'gender': person.gender,
|
||||
{{ 'Born the date'|trans({'gender': person.gender.genderTranslation.value,
|
||||
'birthdate': person.birthdate|format_date("medium") }) }}
|
||||
</time>
|
||||
{%- if options['addAge'] -%}
|
||||
|
@ -2,7 +2,7 @@ Born the date: >-
|
||||
{gender, select,
|
||||
man {Né le {birthdate}}
|
||||
woman {Née le {birthdate}}
|
||||
other {Né·e le {birthdate}}
|
||||
neutral {Né·e le {birthdate}}
|
||||
}
|
||||
|
||||
Requestor: >-
|
||||
|
Loading…
x
Reference in New Issue
Block a user