Skip to content

Type exception when using field_label() form helper #39591

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

Closed
mmarton opened this issue Dec 21, 2020 · 0 comments
Closed

Type exception when using field_label() form helper #39591

mmarton opened this issue Dec 21, 2020 · 0 comments

Comments

@mmarton
Copy link

mmarton commented Dec 21, 2020

Hi!

Symfony version(s) affected: 5.2.1

Description
When i'm trying to use the new form helpers https://symfony.com/blog/new-in-symfony-5-2-form-field-helpers (btw why does this show an unsupported message?) I get a type exception:
Return value of Symfony\Bridge\Twig\Extension\FormExtension::createFieldTranslation() must be of the type string, null returned

How to reproduce

public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('name', TextType::class, ['empty_data' => ''])
            ->add('locked', CheckboxType::class);
        }
    }
{{ form_start(form) }}
        <div class="form-group row">
            <label class="col-form-label col-md-3 col-lg-2">{{ field_label(form.locked) }}</label>
            <div class="col-form-widget col-md-9 col-lg-6">
                {{ form_widget(form.locked) }}
                {{ form_errors(form.locked) }}
            </div>
        </div>
{{ form_end(form) }}

Possible Solution
maybe allow return null in referenced function ant the ones that calling it.
https://github.com/symfony/symfony/blob/5.x/src/Symfony/Bridge/Twig/Extension/FormExtension.php#L167
since it can return null, if the first if statement is true.

cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants