From eb6a893c1ef06ff18419e9070717a8a117658642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Andr=C3=A9?= Date: Mon, 7 Oct 2024 13:03:00 +0200 Subject: [PATCH] Add BC layer for `twig_to_array` deprecation then removal --- src/TwigComponent/src/Twig/ComponentNode.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/TwigComponent/src/Twig/ComponentNode.php b/src/TwigComponent/src/Twig/ComponentNode.php index b8259a228e8..a6427b5c696 100644 --- a/src/TwigComponent/src/Twig/ComponentNode.php +++ b/src/TwigComponent/src/Twig/ComponentNode.php @@ -12,6 +12,7 @@ namespace Symfony\UX\TwigComponent\Twig; use Twig\Compiler; +use Twig\Extension\CoreExtension; use Twig\Node\EmbedNode; use Twig\Node\Expression\AbstractExpression; @@ -34,13 +35,21 @@ public function compile(Compiler $compiler): void { $compiler->addDebugInfo($this); + // since twig/twig 3.9.0: Using the internal "twig_to_array" function is deprecated. + if (method_exists(CoreExtension::class, 'toArray')) { + $twig_to_array = 'Twig\Extension\CoreExtension::toArray'; + } else { + $twig_to_array = 'twig_to_array'; + } + $compiler ->raw('$props = $this->extensions[') ->string(ComponentExtension::class) ->raw(']->embeddedContext(') ->string($this->getAttribute('component')) ->raw(', ') - ->raw('twig_to_array(') + ->raw($twig_to_array) + ->raw('(') ->subcompile($this->getNode('variables')) ->raw('), ') ->raw($this->getAttribute('only') ? '[]' : '$context')