/** * define form fields * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); $builder->add('title', 'text', array('label' => 'menu.form.title.label', 'required' => true))->add('link', 'victoire_link')->remove('removeButton'); /* * When we are editing a menu, we must add the sub menus if there are some children in the entity */ $builder->addEventListener(FormEvents::PRE_SET_DATA, function ($event) { $entity = $event->getData(); if ($entity !== null) { $nbChildren = count($entity->getChildren()); if ($nbChildren > 0) { $form = $event->getForm(); $this->addChildrenField($form); } } }); /* * we use the PRE_SUBMIT event to avoid having a circular reference * * This is done when a widget is created in js in the view */ $builder->addEventListener(FormEvents::PRE_SUBMIT, function ($event) { $rawData = $event->getData(); if (isset($rawData['items'])) { $addChildren = true; } else { $addChildren = false; } //did some children was added in the form if ($addChildren) { $form = $event->getForm(); $this->addChildrenField($form); } }); }
/** * define form fields * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); $builder->add('title', null, array('label' => 'form.listing.FAQ.question.label', 'required' => true))->add('answer', 'textarea', array('label' => 'form.listing.FAQ.answer.label')); }