Skip to content

Commit

Permalink
Add BC layer for twig_to_array deprecation then removal
Browse files Browse the repository at this point in the history
  • Loading branch information
smnandre authored and fabpot committed Oct 7, 2024
1 parent 42b4665 commit eb6a893
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/TwigComponent/src/Twig/ComponentNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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')
Expand Down

0 comments on commit eb6a893

Please sign in to comment.