From 0186ecb30e954603894cf2eb66c9ce9f33213d22 Mon Sep 17 00:00:00 2001 From: Thomas Lallement Date: Fri, 17 Jun 2022 17:20:52 +0200 Subject: [PATCH] Allow passing null in twig_is_selected_choice In the cached file of my application I can see the following code fragment that have been generated by Symfony: ```php if (( !((array_key_exists("render_preferred_choices", $context)) ? (_twig_default_filter((isset($context["render_preferred_choices"]) || array_key_exists("render_preferred_choices", $context) ? $context["render_preferred_choices"] : (function () { throw new RuntimeError('Variable "render_preferred_choices" does not exist.', 88, $this->source); })()), false)) : (false)) && Symfony\Bridge\Twig\Extension\twig_is_selected_choice($context["choice"], (isset($context["value"]) || array_key_exists("value", $context) ? $context["value"] : (function () { throw new RuntimeError('Variable "value" does not exist.', 88, $this->source); })())))) { echo " selected=\"selected\""; } ``` The 2nd Arg passed when calling ``twig_is_selected_choice`` if the result of ``(isset($context["value"]) || array_key_exists("value", $context) ? $context["value"]``. In that condition, if ``$context['value'] = null, we pass the null Currently I got the following error: ``` Symfony\Bridge\Twig\Extension\twig_is_selected_choice(): Argument #2 ($selectedValue) must be of type array|string, null given, called in X:\workspace-novento\novento-vip-lounge\var\cache\admin_dev\twig\01\01615438ee40292438687b29025d08a9.php on line 534 ``` --- src/Symfony/Bridge/Twig/Extension/FormExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index f7d82e042138d..c726b0584d140 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -188,7 +188,7 @@ private function createFieldTranslation(?string $value, array $parameters, strin * * @see ChoiceView::isSelected() */ -function twig_is_selected_choice(ChoiceView $choice, string|array $selectedValue): bool +function twig_is_selected_choice(ChoiceView $choice, string|array|null $selectedValue): bool { if (\is_array($selectedValue)) { return \in_array($choice->value, $selectedValue, true);