wip: use GenderIconEnum to allow user to select bootstrap icon

This commit is contained in:
Julie Lenaerts 2024-09-26 15:45:44 +02:00
parent 67a6eb17db
commit 567c01f395
6 changed files with 30 additions and 13 deletions

View File

@ -30,8 +30,8 @@ class Gender
private GenderEnum $genderTranslation;
#[Serializer\Groups(['read'])]
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255)]
private string $icon = '';
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, enumType: GenderIconEnum::class)]
private GenderIconEnum $icon;
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::FLOAT, name: 'ordering', nullable: true, options: ['default' => '0.0'])]
private float $order = 0;
@ -71,12 +71,12 @@ class Gender
$this->$genderTranslation = $genderTranslation;
}
public function getIcon(): string
public function getIcon(): GenderIconEnum
{
return $this->icon;
}
public function setIcon(string $icon): void
public function setIcon(GenderIconEnum $icon): void
{
$this->icon = $icon;
}

View File

@ -0,0 +1,12 @@
<?php
namespace Chill\MainBundle\Entity;
enum GenderIconEnum: string
{
case MALE = 'bi bi-gender-male';
case FEMALE = 'bi bi-gender-female';
case NEUTRAL = 'bi bi-gender-neuter';
case AMBIGUOUS = 'bi bi-gender-ambiguous';
case TRANS = 'bi bi-gender-trans';
}

View File

@ -4,6 +4,7 @@ namespace Chill\MainBundle\Form;
use Chill\MainBundle\Entity\Gender;
use Chill\MainBundle\Entity\GenderEnum;
use Chill\MainBundle\Entity\GenderIconEnum;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@ -20,7 +21,13 @@ class GenderType extends AbstractType
->add('label', TranslatableStringFormType::class, [
'required' => true,
])
->add('icon', TextType::class)
->add('icon', ChoiceType::class, [
'choices' => GenderIconEnum::cases(),
'expanded' => true,
'multiple' => false,
'mapped' => true,
'label' => 'Select Gender Icon',
])
->add('genderTranslation', ChoiceType::class, [
'choices' => GenderEnum::cases(),
'choice_label' => fn(GenderEnum $enum) => ucfirst(strtolower($enum->name)),

View File

@ -10,6 +10,7 @@ import Modal from 'bootstrap/js/dist/modal';
import Collapse from 'bootstrap/js/src/collapse';
import Carousel from 'bootstrap/js/src/carousel';
import Popover from 'bootstrap/js/src/popover';
import 'bootstrap-icons/font/bootstrap-icons.css';
//
// Carousel: ACHeaderSlider is a small slider used in banner of AccompanyingCourse Section
@ -59,4 +60,4 @@ const popoverList = triggerList.map(function (el) {
return new Popover(el, {
html: true,
});
});
});

View File

@ -85,12 +85,8 @@
{%- endif -%}
</div>
{%- if options['addInfo'] -%}
{% set gender = (person.gender == 'woman') ? 'fa-venus' :
(person.gender == 'man') ? 'fa-mars' : (person.gender == 'both') ? 'fa-neuter' : 'fa-genderless' %}
{% set genderTitle = (person.gender == 'woman') ? 'woman' :
(person.gender == 'man') ? 'man' : (person.gender == 'both') ? 'both' : 'Not given'|trans %}
<p class="moreinfo">
<i class="fa fa-fw {{ gender }}" title="{{ genderTitle|trans }}"></i>
<i class="{{ person.gender.icon }}" title="{{ person.gender.label|localize_translatable_string }}"></i>
{%- if person.deathdate is not null -%}
{%- if person.birthdate is not null -%}

View File

@ -3,13 +3,14 @@ Born the date: >-
man {Né le {birthdate}}
woman {Née le {birthdate}}
neutral {Né·e le {birthdate}}
other {Né·e le {birthdate}}
}
Requestor: >-
{gender, select,
man {Demandeur}
woman {Demandeuse}
other {Demandeur·euse}
neutral {Demandeur·euse}
}
person:
@ -17,7 +18,7 @@ person:
{gender, select,
man {et lui-même}
woman {et elle-même}
other {et lui·elle-même}
neutral {et lui·elle-même}
}
from_the: depuis le