From 67a6eb17db0d0e60209ce70b6442ffe204b0f303 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 26 Sep 2024 13:24:30 +0200 Subject: [PATCH] Change PickGenderType form field to use in Person creation form --- .../ChillMainBundle/Form/GenderType.php | 11 ++-- .../Resources/views/Gender/index.html.twig | 11 +--- .../migrations/Version20240925133053.php | 28 ---------- .../ChillPersonBundle/Entity/Person.php | 14 +---- .../Form/CreationPersonType.php | 4 +- .../ChillPersonBundle/Form/PersonType.php | 4 +- .../Form/Type/GenderType.php | 44 --------------- .../Form/Type/PickGenderType.php | 53 +++++++++++++++++++ .../Resources/views/Entity/person.html.twig | 2 +- .../translations/messages+intl-icu.fr.yaml | 2 +- 10 files changed, 69 insertions(+), 104 deletions(-) delete mode 100644 src/Bundle/ChillMainBundle/migrations/Version20240925133053.php delete mode 100644 src/Bundle/ChillPersonBundle/Form/Type/GenderType.php create mode 100644 src/Bundle/ChillPersonBundle/Form/Type/PickGenderType.php diff --git a/src/Bundle/ChillMainBundle/Form/GenderType.php b/src/Bundle/ChillMainBundle/Form/GenderType.php index 2f188ba58..d6a95e803 100644 --- a/src/Bundle/ChillMainBundle/Form/GenderType.php +++ b/src/Bundle/ChillMainBundle/Form/GenderType.php @@ -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' => [ diff --git a/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig index 82994aaa4..a46fbee56 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig @@ -6,7 +6,7 @@ id {{ 'gender.label'|trans }} {{ 'gender.icon'|trans }} - {{ 'gender.isGrammatical'|trans }} + {{ 'gender.genderTranslation'|trans }} {{ 'gender.active'|trans }} {{ 'gender.ordering'|trans }} @@ -16,15 +16,8 @@ {{ entity.id }} {{ entity.label|localize_translatable_string }} -{# todo: decide which icon source to use#} - - {%- if entity.isGrammatical -%} - - {%- else -%} - - {%- endif -%} - + {{ entity.genderTranslation.value }} {%- if entity.active -%} diff --git a/src/Bundle/ChillMainBundle/migrations/Version20240925133053.php b/src/Bundle/ChillMainBundle/migrations/Version20240925133053.php deleted file mode 100644 index 4767ff3bd..000000000 --- a/src/Bundle/ChillMainBundle/migrations/Version20240925133053.php +++ /dev/null @@ -1,28 +0,0 @@ -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'); - } -} diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index c8ba84797..aa59948df 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -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()) { diff --git a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php index 9bfb75e31..bb40c6c35 100644 --- a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php @@ -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, [ diff --git a/src/Bundle/ChillPersonBundle/Form/PersonType.php b/src/Bundle/ChillPersonBundle/Form/PersonType.php index 21717a25b..0f4fbd8e4 100644 --- a/src/Bundle/ChillPersonBundle/Form/PersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/PersonType.php @@ -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, [ diff --git a/src/Bundle/ChillPersonBundle/Form/Type/GenderType.php b/src/Bundle/ChillPersonBundle/Form/Type/GenderType.php deleted file mode 100644 index 2989b3ec4..000000000 --- a/src/Bundle/ChillPersonBundle/Form/Type/GenderType.php +++ /dev/null @@ -1,44 +0,0 @@ - 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; - } -} diff --git a/src/Bundle/ChillPersonBundle/Form/Type/PickGenderType.php b/src/Bundle/ChillPersonBundle/Form/Type/PickGenderType.php new file mode 100644 index 000000000..4d4552caf --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Form/Type/PickGenderType.php @@ -0,0 +1,53 @@ +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; + } +} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index 5c606e737..bd3ff0ff1 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -106,7 +106,7 @@ {%- endif -%} {%- elseif person.birthdate is not null -%} {%- if options['addAge'] -%} diff --git a/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml b/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml index 9b2edf573..c65e8ccdd 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml +++ b/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml @@ -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: >-