Skip to content

Commit 6b5e43d

Browse files
committed
Fix twig_to_array is deprecated
1 parent 8fe391d commit 6b5e43d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/TwigComponent/src/Twig/ComponentNode.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ public function compile(Compiler $compiler): void
4343
{
4444
$compiler->addDebugInfo($this);
4545

46+
// since twig/twig 3.9.0: Using the internal "twig_to_array" function is deprecated.
47+
$compiler
48+
->write('$toArray = function ($data) {')
49+
->write('if (method_exists(Twig\Extension\CoreExtension::class, \'toArray\')) {')
50+
->write('return Twig\Extension\CoreExtension::toArray($data);')
51+
->write('}')
52+
->write('return twig_to_array($data);')
53+
->write('};')
54+
;
55+
4656
/*
4757
* Block 1) PreCreateForRender handling
4858
*
@@ -55,7 +65,7 @@ public function compile(Compiler $compiler): void
5565
->raw(']->extensionPreCreateForRender(')
5666
->string($this->getAttribute('component'))
5767
->raw(', ')
58-
->raw('twig_to_array(')
68+
->raw('$toArray(')
5969
;
6070
$this->writeProps($compiler)
6171
->raw(')')
@@ -86,7 +96,7 @@ public function compile(Compiler $compiler): void
8696
->string(ComponentExtension::class)
8797
->raw(']->startEmbeddedComponentRender(')
8898
->string($this->getAttribute('component'))
89-
->raw(', twig_to_array(')
99+
->raw(', $toArray(')
90100
;
91101
$this->writeProps($compiler)
92102
->raw('), ')

0 commit comments

Comments
 (0)