From 43dd94dad6847b0293f176f6564682b9bb4f7b58 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 1 Oct 2024 11:36:00 +0200 Subject: [PATCH] Use renderInterface to render gender icons in twig --- .../Resources/views/Gender/index.html.twig | 2 +- .../Entity/ChillGenderIconRender.php | 37 +++++++++++++++++++ .../config/services/templating.yaml | 2 + .../Resources/views/Entity/person.html.twig | 3 +- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Templating/Entity/ChillGenderIconRender.php diff --git a/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig index a46fbee56..b93d8ba90 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Gender/index.html.twig @@ -16,7 +16,7 @@ {{ entity.id }} {{ entity.label|localize_translatable_string }} - + {{ entity.icon|chill_entity_render_box }} {{ entity.genderTranslation.value }} {%- if entity.active -%} diff --git a/src/Bundle/ChillMainBundle/Templating/Entity/ChillGenderIconRender.php b/src/Bundle/ChillMainBundle/Templating/Entity/ChillGenderIconRender.php new file mode 100644 index 000000000..7494908cb --- /dev/null +++ b/src/Bundle/ChillMainBundle/Templating/Entity/ChillGenderIconRender.php @@ -0,0 +1,37 @@ + + */ +final readonly class ChillGenderIconRender implements ChillEntityRenderInterface +{ + public function renderBox($icon, array $options): string + { + return + ''; + } + + public function renderString($icon, array $options): string + { + return $icon->value; + } + + public function supports($icon, array $options): bool + { + return $icon instanceof GenderIconEnum; + } +} diff --git a/src/Bundle/ChillMainBundle/config/services/templating.yaml b/src/Bundle/ChillMainBundle/config/services/templating.yaml index 0baa91b69..dc21b07f5 100644 --- a/src/Bundle/ChillMainBundle/config/services/templating.yaml +++ b/src/Bundle/ChillMainBundle/config/services/templating.yaml @@ -49,6 +49,8 @@ services: Chill\MainBundle\Templating\Entity\NewsItemRender: ~ + Chill\MainBundle\Templating\Entity\ChillGenderIconRender: ~ + Chill\MainBundle\Templating\Entity\UserRender: ~ Chill\MainBundle\Templating\Listing\: diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index 7c3c02abe..776d87132 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -86,7 +86,8 @@ {%- if options['addInfo'] -%}

- + {{ person.gender.icon|chill_entity_render_box }} +{# #} {%- if person.deathdate is not null -%} {%- if person.birthdate is not null -%}