Skip to content

Commit

Permalink
Merge branch '6.3' into 6.4
Browse files Browse the repository at this point in the history
* 6.3:
  don't use deprecated and internal Twig functions
  [Notifier][Clickatell] Fixed minor typo
  add missing translation
  [Messenger] Add missing Redis cleanup in tests
  Make sure Serializer::denormalize have show what exception it throws
  • Loading branch information
fabpot committed Dec 15, 2023
2 parents 142bc3a + 42c5bfd commit 97af829
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 8 additions & 2 deletions Node/SearchAndRenderBlockNode.php
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bridge\Twig\Node;

use Twig\Compiler;
use Twig\Extension\CoreExtension;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FunctionExpression;
Expand Down Expand Up @@ -50,7 +51,7 @@ public function compile(Compiler $compiler): void
$labelIsExpression = false;

// Only insert the label into the array if it is not empty
if (!twig_test_empty($label->getAttribute('value'))) {
if (null !== $label->getAttribute('value') && false !== $label->getAttribute('value') && '' !== (string) $label->getAttribute('value')) {
$originalVariables = $variables;
$variables = new ArrayExpression([], $lineno);
$labelKey = new ConstantExpression('label', $lineno);
Expand Down Expand Up @@ -97,7 +98,12 @@ public function compile(Compiler $compiler): void

// Check at runtime whether the label is empty.
// If not, add it to the array at runtime.
$compiler->raw('(twig_test_empty($_label_ = ');
if (method_exists(CoreExtension::class, 'testEmpty')) {
$compiler->raw('(CoreExtension::testEmpty($_label_ = ');
} else {
$compiler->raw('(twig_test_empty($_label_ = ');
}

$compiler->subcompile($label);
$compiler->raw(') ? [] : ["label" => $_label_])');
}
Expand Down
11 changes: 7 additions & 4 deletions Tests/Node/SearchAndRenderBlockNodeTest.php
Expand Up @@ -15,6 +15,7 @@
use Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode;
use Twig\Compiler;
use Twig\Environment;
use Twig\Extension\CoreExtension;
use Twig\Loader\LoaderInterface;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\ConditionalExpression;
Expand Down Expand Up @@ -226,8 +227,9 @@ public function testCompileLabelWithLabelThatEvaluatesToNull()
// https://github.com/symfony/symfony/issues/5029
$this->assertEquals(
sprintf(
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))',
$this->getVariableGetter('form')
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', (%s($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))',
$this->getVariableGetter('form'),
method_exists(CoreExtension::class, 'testEmpty') ? 'CoreExtension::testEmpty' : 'twig_test_empty'
),
trim($compiler->compile($node)->getSource())
);
Expand Down Expand Up @@ -263,8 +265,9 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
// https://github.com/symfony/symfony/issues/5029
$this->assertEquals(
sprintf(
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', ["foo" => "bar", "label" => "value in attributes"] + (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))',
$this->getVariableGetter('form')
'$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->searchAndRenderBlock(%s, \'label\', ["foo" => "bar", "label" => "value in attributes"] + (%s($_label_ = ((true) ? (null) : (null))) ? [] : ["label" => $_label_]))',
$this->getVariableGetter('form'),
method_exists(CoreExtension::class, 'testEmpty') ? 'CoreExtension::testEmpty' : 'twig_test_empty'
),
trim($compiler->compile($node)->getSource())
);
Expand Down

0 comments on commit 97af829

Please sign in to comment.