Add UserGroupRender and Interface for UserGroup templating

A new UserGroupRender class was added to manage the templating logic for UserGroup entities. The UserGroupRenderInterface was also created, extending the ChillEntityRenderInterface. Additionally, a Twig template for rendering user groups was added.
This commit is contained in:
Julien Fastré 2024-05-31 12:31:44 +02:00
parent e6202a2e34
commit 50025044d3
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
4 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1 @@
<span class="badge" style="color: {{ user_group.foregroundColor }}; background-color: {{ user_group.backgroundColor }};">{{ user_group.label|localize_translatable_string }}</span>

View File

@ -0,0 +1,38 @@
<?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\UserGroup;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Twig\Environment;
final readonly class UserGroupRender implements UserGroupRenderInterface
{
public function __construct(private TranslatableStringHelperInterface $translatableStringHelper, private Environment $environment) {}
public function renderBox($entity, array $options): string
{
/* @var $entity UserGroup */
return $this->environment->render('@ChillMain/Entity/user_group.html.twig', ['user_group' => $entity]);
}
public function renderString($entity, array $options): string
{
/* @var $entity UserGroup */
return $this->translatableStringHelper->localize($entity->getLabel());
}
public function supports(object $entity, array $options): bool
{
return $entity instanceof UserGroup;
}
}

View File

@ -0,0 +1,14 @@
<?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;
interface UserGroupRenderInterface extends ChillEntityRenderInterface {}

View File

@ -51,6 +51,10 @@ services:
Chill\MainBundle\Templating\Entity\UserRender: ~
Chill\MainBundle\Templating\Entity\UserGroupRender: ~
Chill\MainBundle\Templating\Entity\UserGroupRenderInterface:
alias: Chill\MainBundle\Templating\Entity\UserGroupRender
Chill\MainBundle\Templating\Listing\:
resource: './../../Templating/Listing'