Use renderInterface to render gender icons in twig

This commit is contained in:
Julie Lenaerts 2024-10-01 11:36:00 +02:00
parent 567c01f395
commit b9d2f5efa3
4 changed files with 42 additions and 2 deletions

View File

@ -16,7 +16,7 @@
<tr> <tr>
<td>{{ entity.id }}</td> <td>{{ entity.id }}</td>
<td>{{ entity.label|localize_translatable_string }}</td> <td>{{ entity.label|localize_translatable_string }}</td>
<td><i class="{{ entity.icon }}"></i></td> <td>{{ entity.icon|chill_entity_render_box }}</td>
<td>{{ entity.genderTranslation.value }}</td> <td>{{ entity.genderTranslation.value }}</td>
<td style="text-align:center;"> <td style="text-align:center;">
{%- if entity.active -%} {%- if entity.active -%}

View File

@ -0,0 +1,37 @@
<?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\MainBundle\Templating\Entity;
use Chill\MainBundle\Entity\GenderIconEnum;
use Chill\MainBundle\Entity\NewsItem;
/**
* @implements ChillEntityRenderInterface<GenderIconEnum>
*/
final readonly class ChillGenderIconRender implements ChillEntityRenderInterface
{
public function renderBox($icon, array $options): string
{
return
'<i class="'. $icon->value .'"></i>';
}
public function renderString($icon, array $options): string
{
return $icon->value;
}
public function supports($icon, array $options): bool
{
return $icon instanceof GenderIconEnum;
}
}

View File

@ -49,6 +49,8 @@ services:
Chill\MainBundle\Templating\Entity\NewsItemRender: ~ Chill\MainBundle\Templating\Entity\NewsItemRender: ~
Chill\MainBundle\Templating\Entity\ChillGenderIconRender: ~
Chill\MainBundle\Templating\Entity\UserRender: ~ Chill\MainBundle\Templating\Entity\UserRender: ~
Chill\MainBundle\Templating\Listing\: Chill\MainBundle\Templating\Listing\:

View File

@ -86,7 +86,8 @@
</div> </div>
{%- if options['addInfo'] -%} {%- if options['addInfo'] -%}
<p class="moreinfo"> <p class="moreinfo">
<i class="{{ person.gender.icon }}" title="{{ person.gender.label|localize_translatable_string }}"></i> {{ person.gender.icon|chill_entity_render_box }}
{# <i class="{{ person.gender.icon.value }}" title="{{ person.gender.label|localize_translatable_string }}"></i>#}
{%- if person.deathdate is not null -%} {%- if person.deathdate is not null -%}
{%- if person.birthdate is not null -%} {%- if person.birthdate is not null -%}