Refactor WidgetRenderingTwig: remove TwigFunction usage, replace with attributes for declaring functions.

This commit is contained in:
2025-12-22 15:29:05 +01:00
parent 22c3952c00
commit 14a0c2b4fd

View File

@@ -15,7 +15,6 @@ use Chill\MainBundle\Templating\Events\DelegatedBlockRenderingEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Twig\DeprecatedCallableInfo;
use Twig\Environment;
use Twig\TwigFunction;
/**
* Add the function `chill_delegated_block`.
@@ -83,27 +82,13 @@ class WidgetRenderingTwig
$this->widget[$place][$ordering] = [$widget, $config];
}
public function getFunctions(): array
{
return [
new TwigFunction(
'chill_delegated_block',
$this->renderingWidget(...),
[
'is_safe' => ['html'],
'needs_environment' => true,
'deprecated' => true, 'alternative' => 'chill_widget',
]
),
];
}
public function getName()
{
return 'chill_main_widget';
}
#[\Twig\Attribute\AsTwigFunction('chill_widget', needsEnvironment: true, isSafe: ['html'], deprecationInfo: new DeprecatedCallableInfo('chill-project/chill-bundles', '3.0'))]
#[\Twig\Attribute\AsTwigFunction('chill_widget', needsEnvironment: true, isSafe: ['html'])]
#[\Twig\Attribute\AsTwigFunction('chill_delegated_block', 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