Refactor Twig extensions to use attributes for declaring functions and filters, remove AbstractExtension inheritance, and clean up related service definitions.

This commit is contained in:
2025-12-19 12:23:20 +01:00
parent 0d42ed9262
commit 741f655cfc
19 changed files with 72 additions and 244 deletions

View File

@@ -17,31 +17,17 @@ use Twig\TwigFilter;
/**
* Class ChillEntityRenderExtension.
*/
class ChillEntityRenderExtension extends AbstractExtension
class ChillEntityRenderExtension
{
public function __construct(private readonly ChillEntityRenderManagerInterface $renderManager) {}
/**
* @return array|TwigFilter[]
*/
#[\Override]
public function getFilters()
{
return [
new TwigFilter('chill_entity_render_string', $this->renderString(...), [
'is_safe' => ['html'],
]),
new TwigFilter('chill_entity_render_box', $this->renderBox(...), [
'is_safe' => ['html'],
]),
];
}
#[\Twig\Attribute\AsTwigFilter('chill_entity_render_box', isSafe: ['html'])]
public function renderBox(?object $entity, array $options = []): string
{
return $this->renderManager->renderBox($entity, $options);
}
#[\Twig\Attribute\AsTwigFilter('chill_entity_render_string', isSafe: ['html'])]
public function renderString(?object $entity, array $options = []): string
{
return $this->renderManager->renderString($entity, $options);