Symfony\Bundle\FrameworkBundle\Controller\Controller::createFormBuilder PHP Method

createFormBuilder() protected method

Creates and returns a form builder instance.
protected createFormBuilder ( mixed $data = null, array $options = [] ) : FormBuilder
$data mixed The initial data for the form
$options array Options for the form
return Symfony\Component\Form\FormBuilder
    protected function createFormBuilder($data = null, array $options = array())
    {
        return $this->container->get('form.factory')->createBuilder(FormType::class, $data, $options);
    }

Usage Example

 public function onController(Controller $controller, Request $request)
 {
     $object = $this->admin->newObject();
     $label = null;
     if ($this->admin->tree && $this->admin->getTreeObjectId()) {
         $label = $this->admin->trans('sf.tree.create.title', array('%object%' => $this->admin->string($this->admin->getTreeObject()), '%admin%' => $this->admin->getLabel()), $this->sf_domain);
     } else {
         $label = $this->admin->getFormLabel();
     }
     $list_url = $this->admin->path('list');
     $this->admin->setFormOriginalObject($object);
     $builder = $controller->createFormBuilder($object, array('label' => $label));
     $this->admin->buildCreateForm($controller, $object, $builder, $this);
     $this->buildFormReferer($request, $builder, $object, $list_url);
     $form = $builder->getForm();
     $this->setForm($form);
     $dispatcher = $this->admin->getService('event_dispatcher');
     $event = new \Symforce\AdminBundle\Event\FormEvent($form, $request);
     $dispatcher->dispatch('sf.event.form', $event);
     if (null !== $event->getResponse()) {
         return $event->getResponse();
     }
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         $this->admin->fireEvent('submit', $form);
         if ($form->isValid()) {
             $this->admin->onUpdate($controller, $request, $this, $object, $form);
             if ($form->isValid()) {
                 $this->admin->update($object);
                 return $this->admin->afterUpdate($controller, $request, $this, $object, $form);
             }
         }
     }
     return $controller->render($this->template, array('sf_admin_loader' => $controller->get('sf.admin.loader'), 'admin' => $this->admin, 'action' => $this, 'form' => $form->createView()));
 }
All Usage Examples Of Symfony\Bundle\FrameworkBundle\Controller\Controller::createFormBuilder