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

@@ -13,8 +13,8 @@ namespace Chill\MainBundle\Templating\Widget;
use Chill\MainBundle\Templating\Events\DelegatedBlockRenderingEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Twig\DeprecatedCallableInfo;
use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
/**
@@ -40,7 +40,7 @@ use Twig\TwigFunction;
* `Chill\MainBundle\Templating\Events\DelegatedBlockRenderingEvent`
* for usage of this event class
*/
class WidgetRenderingTwig extends AbstractExtension
class WidgetRenderingTwig
{
/**
* @var EventDispatcherInterface
@@ -83,8 +83,7 @@ class WidgetRenderingTwig extends AbstractExtension
$this->widget[$place][$ordering] = [$widget, $config];
}
#[\Override]
public function getFunctions()
public function getFunctions(): array
{
return [
new TwigFunction(
@@ -96,11 +95,6 @@ class WidgetRenderingTwig extends AbstractExtension
'deprecated' => true, 'alternative' => 'chill_widget',
]
),
new TwigFunction(
'chill_widget',
$this->renderingWidget(...),
['is_safe' => ['html'], 'needs_environment' => true]
),
];
}
@@ -109,7 +103,8 @@ class WidgetRenderingTwig extends AbstractExtension
return 'chill_main_widget';
}
public function renderingWidget(Environment $env, $block, array $context = [])
#[\Twig\Attribute\AsTwigFunction('chill_widget', needsEnvironment: true, isSafe: ['html'], deprecationInfo: new DeprecatedCallableInfo('chill-project/chill-bundles', '3.0'))]
public function renderingWidget(Environment $env, $block, array $context = []): string
{
// get the content of widgets
$content = '';