Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow passing null in twig_is_selected_choice #46704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2022
Merged

Conversation

raziel057
Copy link
Contributor

@raziel057 raziel057 commented Jun 17, 2022

Q A
Branch? 6.0 and >
Bug fix? yes
New feature? no
Deprecations? no
License MIT

In the cached file of my application, generated by Symfony I can see the following code fragment:

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 is the result of (isset($context["value"]) || array_key_exists("value", $context) ? $context["value"]. So in case $context['value'] = null, we pass null as 2nd arg of twig_is_selected_choice.

As a result in some case, when I submit form with empty (null) value, 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 ...\var\cache\dev\twig\01\01615438ee40292438687b29025d08a9.php on line 534

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 symfony#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
```
@raziel057 raziel057 requested a review from xabbuh as a code owner June 17, 2022 15:23
@carsonbot carsonbot added this to the 6.0 milestone Jun 17, 2022
@fabpot
Copy link
Member

fabpot commented Jun 17, 2022

Thank you @raziel057.

@fabpot fabpot merged commit fac84a0 into symfony:6.0 Jun 17, 2022
This was referenced Jun 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants