Using form parameters, as you suggest, you can define your type of form with something like:
class FormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('first_name',TextType::class,array('disabled'=>$option['first_name_disabled'])); } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array('first_name_disabled'=>false)); } }
And then in your controller create a form with:
$form=$this->createForm(MyType::class, $yourEntity, array('first_name_disabled'=>$disableFirstNameField));
But if the value is disabled, it depends on the value in the entity, you should rather use formevent:
use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('first_name',TextType::class);
source share