Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony Forms: options not working

I have a symfony 3.4 form class UserForm and I set the option 'password_field' => false in the setDefaultOptions method:

public function setDefaultOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => User::class,
        'password_field' => false,
    ));
}

In my controller where I'm using this form, I set the option:

    $form = $this->createForm(UserForm::class, $user, [
        'password_field' => false,
    ]);

By loading the form in the browser, I get the following error message:

The option "password_field" does not exist. Defined options are: "action", "allow_extra_fields", "attr", "auto_initialize", "block_name", "by_reference", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "inherit_data", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "mapped", "method", "post_max_size_message", "property_path", "required", "translation_domain", "trim", "upload_max_size_message", "validation_groups".

Everything looks right to me, as described in the documentation. Any ideas?


1 Answers

setDefaultOptions() has been deprecated in favor of configureOptions(). This method name was used in Symfony 2.x

See UPGRADE-3.0.md.

configureOptions() is already used in Symfony 3.x

So you have to replace method names ;)

Example:

/**
 * @param OptionsResolver $resolver
 */
public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults([
        'data_class' => User::class,
        'password_field' => false
    ]);
}
like image 185
Mateusz Palichleb Avatar answered Mar 10 '26 12:03

Mateusz Palichleb