public function editAction(Request $request, $id)
    {
        $formManager = $this->get('opifer.form.form_manager');
        $em = $this->get('doctrine.orm.entity_manager');

        $form = $formManager->getRepository()->find($id);

        if (!$form) {
            return $this->createNotFoundException();
        }

        $originalAttributes = new ArrayCollection();
        foreach ($form->getSchema()->getAttributes() as $attributes) {
            $originalAttributes->add($attributes);
        }

        $formType = $this->createForm(FormType::class, $form);
        $formType->handleRequest($request);

        if ($formType->isSubmitted() && $formType->isValid()) {
            // Remove deleted attributes
            foreach ($originalAttributes as $attribute) {
                if (false === $form->getSchema()->getAttributes()->contains($attribute)) {
                    $em->remove($attribute);
                }
            }

            // Add new attributes
            foreach ($formType->getData()->getSchema()->getAttributes() as $attribute) {
                $attribute->setSchema($form->getSchema());

                foreach ($attribute->getOptions() as $option) {
                    $option->setAttribute($attribute);
                }
            }

            $formManager->save($form);

            $this->addFlash('success', 'Event has been updated successfully');

            return $this->redirectToRoute('opifer_form_form_edit', ['id' => $form->getId()]);
        }

        return $this->render($this->getParameter('opifer_form.form_edit_view'), [
            'form' => $form,
            'form_form' => $formType->createView(),
        ]);
    }
public function editAction(Request $request, $id)
    {
        $formManager = $this->get('opifer.form.form_manager');
        $em = $this->get('doctrine.orm.entity_manager');

        $form = $formManager->getRepository()->find($id);

        if (!$form) {
            return $this->createNotFoundException();
        }

        $originalAttributes = new ArrayCollection();
        foreach ($form->getSchema()->getAttributes() as $attributes) {
            $originalAttributes->add($attributes);
        }

        $formType = $this->createForm(FormType::class, $form);
        $formType->handleRequest($request);

        if ($formType->isSubmitted() && $formType->isValid()) {
            // Remove deleted attributes
            foreach ($originalAttributes as $attribute) {
                if (false === $form->getSchema()->getAttributes()->contains($attribute)) {
                    $em->remove($attribute);
                }
            }

            // Add new attributes
            foreach ($formType->getData()->getSchema()->getAttributes() as $attribute) {
                $attribute->setSchema($form->getSchema());

                foreach ($attribute->getOptions() as $option) {
                    $option->setAttribute($attribute);
                }
            }

            $formManager->save($form);

            $this->addFlash('success', 'Event has been updated successfully');

            return $this->redirectToRoute('opifer_form_form_edit', ['id' => $form->getId()]);
        }

        return $this->render($this->getParameter('opifer_form.form_edit_view'), [
            'form' => $form,
            'form_form' => $formType->createView(),
        ]);
    }
public function editAction ( Request $ request , $ id ) { $ formManager = $ this -> get ( 'opifer.form.form_manager' ) ; $ em = $ this -> get ( 'doctrine.orm.entity_manager' ) ; $ form = $ formManager -> getRepository ( ) -> find ( $ id ) ; if ( ! $ form ) { return $ this -> createNotFoundException ( ) ; } $ originalAttributes = new ArrayCollection ( ) ; foreach ( $ form -> getSchema ( ) -> getAttributes ( ) as $ attributes ) { $ originalAttributes -> add ( $ attributes ) ; } $ formType = $ this -> createForm ( FormType :: class , $ form ) ; $ formType -> handleRequest ( $ request ) ; if ( $ formType -> isSubmitted ( ) && $ formType -> isValid ( ) ) { // Remove deleted attributes foreach ( $ originalAttributes as $ attribute ) { if ( false === $ form -> getSchema ( ) -> getAttributes ( ) -> contains ( $ attribute ) ) { $ em -> remove ( $ attribute ) ; } } // Add new attributes foreach ( $ formType -> getData ( ) -> getSchema ( ) -> getAttributes ( ) as $ attribute ) { $ attribute -> setSchema ( $ form -> getSchema ( ) ) ; foreach ( $ attribute -> getOptions ( ) as $ option ) { $ option -> setAttribute ( $ attribute ) ; } } $ formManager -> save ( $ form ) ; $ this -> addFlash ( 'success' , 'Event has been updated successfully' ) ; return $ this -> redirectToRoute ( 'opifer_form_form_edit' , [ 'id' => $ form -> getId ( ) ] ) ; } return $ this -> render ( $ this -> getParameter ( 'opifer_form.form_edit_view' ) , [ 'form' => $ form , 'form_form' => $ formType -> createView ( ) , ] ) ; }
Edit a form.

@param Request $request
@param int     $id

@return RedirectResponse|Response
Edit a form .