diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index 622318643..b60325bec 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -11,6 +11,7 @@ * addCenter bool * hLevel integer * addDeath bool + * addAgeBadge bool * address_multiline bool * customButtons [ 'before' Twig\Markup, (injected with macro) @@ -40,6 +41,11 @@ {%- endfor -%} {%- endif -%} + {%- if options['addAgeBadge'] -%} + {% if person.age is not null and person.deathDate is null %} + ({{- 'years_old'|trans({ 'age': person.age }) -}}) + {% endif %} + {% endif %} {% endmacro raw %} {% macro label(person, options) %} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/_render_member.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/_render_member.html.twig index 5b41a15e3..fdd1e0717 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/_render_member.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/_render_member.html.twig @@ -14,6 +14,7 @@ 'render': 'label', 'addLink': true, 'addInfo': true, + 'addAgeBadge': true, 'customArea': { 'afterLabel': _self.addHolder(member.holder) } diff --git a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php index 6464500c2..ff239f0d6 100644 --- a/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php +++ b/src/Bundle/ChillPersonBundle/Templating/Entity/PersonRender.php @@ -15,6 +15,7 @@ use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender; use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper; use Chill\PersonBundle\Entity\Person; use Symfony\Component\Templating\EngineInterface; +use Symfony\Contracts\Translation\TranslatorInterface; use function array_key_exists; @@ -27,12 +28,16 @@ class PersonRender extends AbstractChillEntityRender private EngineInterface $engine; + private TranslatorInterface $translator; + public function __construct( ConfigPersonAltNamesHelper $configAltNamesHelper, - EngineInterface $engine + EngineInterface $engine, + TranslatorInterface $translator ) { $this->configAltNamesHelper = $configAltNamesHelper; $this->engine = $engine; + $this->translator = $translator; } /** @@ -53,6 +58,7 @@ class PersonRender extends AbstractChillEntityRender 'customButtons' => $options['customButtons'] ?? [], 'customArea' => $options['customArea'] ?? [], 'addDeath' => $options['addDeath'] ?? true, + 'addAgeBadge' => $options['addAgeBadge'] ?? false, ]; return @@ -70,6 +76,11 @@ class PersonRender extends AbstractChillEntityRender */ public function renderString($person, array $options): string { + if (null !== $person->getAge() && $person->getDeathDate() === null) { + return $person->getFirstName() . ' ' . $person->getLastName() + . $this->addAltNames($person, false) . ' (' . $this->translator->trans('years_old', ['age' => $person->getAge()]) . ')'; + } + return $person->getFirstName() . ' ' . $person->getLastName() . $this->addAltNames($person, false); }