Write a page, this method is used by both POST and PUT action methods.

@param Request  $request Symfony request
@param int|null $id      A page identifier

@return FormInterface
966909
protected function handleWritePage($request, $id = null)
    {
        $page = $id ? $this->getPage($id) : null;

        $form = $this->formFactory->createNamed(null, 'sonata_page_api_form_page', $page, [
            'csrf_protection' => false,
        ]);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $page = $form->getData();
            $this->pageManager->save($page);

            return $this->serializeContext($page, ['sonata_api_read']);
        }

        return $form;
    }
1349169
protected function handleWriteGroup($request, $id = null)
    {
        $groupClassName = $this->groupManager->getClass();
        $group = $id ? $this->getGroup($id) : new $groupClassName('');

        $form = $this->formFactory->createNamed(null, 'sonata_user_api_form_group', $group, [
            'csrf_protection' => false,
        ]);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $group = $form->getData();
            $this->groupManager->updateGroup($group);

            $context = new Context();
            $context->setGroups(['sonata_api_read']);
            $context->enableMaxDepth();

            $view = FOSRestView::create($group);
            $view->setContext($context);

            return $view;
        }

        return $form;
    }
567439
public function updateAction(Request $request, $id)
    {
        $em = $this->getDoctrine()->getManager();

        $user = $em->getRepository('ChillMainBundle:User')->find($id);

        if (!$user) {
            throw $this->createNotFoundException('Unable to find User entity.');
        }

        $editForm = $this->createEditForm($user);
        $editForm->handleRequest($request);

        if ($editForm->isValid()) {
            $em->flush();

            return $this->redirect($this->generateUrl('admin_user_edit', array('id' => $id)));
        }

        return $this->render('ChillMainBundle:User:edit.html.twig', array(
            'entity'      => $user,
            'edit_form'   => $editForm->createView(),
            'add_groupcenter_form' => $this->createAddLinkGroupCenterForm($user)->createView(),
            'delete_groupcenter_form' => array_map( 
                    function(\Symfony\Component\Form\Form $form) {
                        return $form->createView();
                
                    },
                    iterator_to_array($this->getDeleteLinkGroupCenterByUser($user), true))
        ));
    }
254491
public function create(Request $request, FormBuilder $formBuilder, $id)
    {
        // Set roles that have access
        $request->user()->authorizeRoles(['admin', 'editor']);

        // Check if pagetype id exist, otherwise gtfo
        if (!$id) {
            return redirect()->route('admin.pages.page.select');
        }

        // Get pagetype, or fail..
        $pagetype = PageType::findOrFail($id);

        // Get fields
        $fields = $pagetype->fields ?: [];

        // Build the form
        $form = $formBuilder->createByArray($fields, [
            'method' => 'POST',
            'url' => route('admin.pages.page.store'),
            'name' => 'content'
        ]);

        return view('page::pages.create', [
            'pagetype' => $pagetype,
            'form' => $form
        ]);
    }
293562
protected function crudCreate(Request $request = null)
    {
        try{
            
            $entity = $this->getEntity();
            $form = $this->createAndBindForm($request, $this->getEntityType() , $entity);
            $page = static::NEW_VIEW;
            
            if ($form->isValid()) {
                $this->saveEntity($entity);                
                if($request->get('_loop_create')){
                    $form = $this->createForm($this->getEntityType(), $this->getEntity());
                }else{
                    $page = static::SHOW_VIEW;
                    $form = $this->createDeleteForm($entity->getId());
                }
                $form = $form->createView();
                return $this->render($page, $this->commonsResponseVars(compact('entity','form')));
            }
            $form = $form->createView();
            return $this->success($page, $this->commonsResponseVars(compact('entity','form')));
            
        }catch(\Exception $e){
          return $this->failure($e);
        }
    }
1008460
public function update(Request $request, $id)
    {
        /** @var \SymfonyId\AdminBundle\Configuration\ConfiguratorFactory $configuratorFactory */
        $configuratorFactory = $this->getConfiguratorFactory($this->getClassName());
        /** @var CrudConfigurator $crudConfigurator */
        $crudConfigurator = $configuratorFactory->getConfigurator(CrudConfigurator::class);

        $this->isGrantedOr404Error($crudConfigurator, Constants::ACTION_UPDATE);

        /** @var ModelInterface $model */
        $model = $this->findOr404Error($id);
        $form = $crudConfigurator->getForm($model, 'PUT');

        return $this->save($request, $form, $crudConfigurator);
    }
238796
public function addAction(Request $request, $id) 
    {
        $em = $this->getDoctrine()->getManager();
        $actor = $em->getRepository($this->get('core_manager')->getActorBundleName().':Actor')->findOneById($id);
        
        $trans = $this->get('translator');
        $form = $this->container->get('form.factory')->create('CoreBundle\Form\ActorRoleType');
        $form->handleRequest($request);
           
        if ($form->isSubmitted()) {
            $em = $this->getDoctrine()->getManager();
            $data = $request->request->get($form->getName());
            $role = $em->getRepository('CoreBundle:Role')->find($data['roles']);
            $actor->addRole($role);
            try {
                $em->persist($actor);
                $em->flush($actor);
                return new JsonResponse(array('status' => 'success', 'id'=> $actor->getId(), 'message'=> $trans->trans('role.created')));
            } catch (\Exception $exc) {
                return new JsonResponse(array('status' => 'error', 'message'=> $trans->trans('role.duplicate')));
            }
        }
        return new JsonResponse(array('status' => 'error', 'message'=> $trans->trans('role.form.notsubmit')));
    }
1116936
public function putAction(Request $request, $id)
    {
        $language = $this->getLanguage($request);
        $action = $request->get('action');

        $this->checkActionParameterSecurity($action, $language, $id);

        $document = $this->getDocumentManager()->find(
            $id,
            $language,
            [
                'load_ghost_content' => false,
                'load_shadow_content' => false,
            ]
        );

        $formType = $this->getMetadataFactory()->getMetadataForClass(get_class($document))->getFormType();

        $this->get('sulu_hash.request_hash_checker')->checkHash($request, $document, $document->getUuid());

        $this->persistDocument($request, $formType, $document, $language);
        $this->handleActionParameter($action, $document, $language);
        $this->getDocumentManager()->flush();

        $context = new Context();
        $context->setGroups(['defaultPage']);

        return $this->handleView($this->view($document)->setContext($context));
    }
1181464
public function update(Request $request, $id)
    {
        $entry = $this->entriesRepository->getById($id, $this->resource);
        $this->validate($request, $this->validationRules($this->resource, $entry));

        $this->entriesRepository->update($id, $request, $this->resource);

        return redirect()->back()->with('success', 'Updated');
    }
1067826
protected function handleWriteUser($request, $id = null)
    {
        $user = $id ? $this->getUser($id) : null;

        $form = $this->formFactory->createNamed(null, 'sonata_user_api_form_user', $user, [
            'csrf_protection' => false,
        ]);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $user = $form->getData();
            $this->userManager->updateUser($user);

            $context = new Context();
            $context->setGroups(['sonata_api_read']);
            $context->enableMaxDepth();

            $view = FOSRestView::create($user);
            $view->setContext($context);

            return $view;
        }

        return $form;
    }
738224
public function editBlockAction(Request $request, $id)
    {
        /** @var BlockManager $manager */
        $manager = $this->get('opifer.content.block_manager');
        $block = $manager->find($id, true);

        /** @var AbstractBlockService $service */
        $service = $manager->getService($block);
        $updatePreview = false; // signals parent window preview from iframe to update preview

        $service->preFormSubmit($block);

        $form = $this->createForm(BlockAdapterFormType::class, $block, [
            'block_service' => $service,
        ]);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $service->postFormSubmit($form, $block);

            $manager->save($block, true);
            $updatePreview = true;
        }

        $viewResponse = $this->render($service->getEditView(), [
            'block_service' => $service,
            'block' => $block,
            'form' => $form->createView(),
            'update_preview' => $updatePreview
        ]);

        return new JsonResponse([
            'title' => $service->getName($block),
            'view' => $viewResponse->getContent(),
            'updatePreview' => $updatePreview
        ]);
    }
1078637
public function editAction($id, Request $request)
    {
        $form = $this->container->get('form.factory')->createNamed(
            'skeleton',
            EditionType::class,
            $template = $this->container->get('synapse.template.loader')
                ->retrieveAll(array('id' => $id, 'scope' => TemplateInterface::GLOBAL_SCOPE))
                ->first(),
            array(
                'theme' => $request->attributes->get(
                    'synapse_theme',
                    $this->container->get('synapse')
                        ->enableDefaultTheme()
                        ->getCurrentTheme()
                ),
                'content_type' => $template->getContentType(),
                'action' => $formUrl = $this->container->get('router')->generate(
                    'synapse_admin_skeleton_edition',
                    array('id' => $template->getId())
                ),
                'method' => 'POST',
                'csrf_protection' => false,
            )
        );
        if ($request->request->has('skeleton')) {
            $form->handleRequest($request);
            if ($form->isValid()) {
                return $this->redirect(
                    $this->container->get('router')->generate(
                        'synapse_admin_skeleton_edition',
                        array('id' => $template->getId())
                    )
                );
            }
        }

        return $this->render('SynapseAdminBundle:Skeleton:edit.html.twig', array(
            'skeleton' => $template,
            'form' => $form->createView(),
        ));
    }
10256
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(),
        ]);
    }
466579
public function getAction(Request $request, $id)
    {
        if (null !== $request->get('fields')) {
            return $this->getContent($request, $id);
        }

        return $this->getSingleNode($request, $id);
    }
733693
public function baseAction(Request $request, int $id = null)
    {
        foreach ($this->breadcrumbs as $breadcrumb) {
            $uri = '';
            if ($breadcrumb['route'] !== '') {
                $uri = $this->router->generate($breadcrumb['route']);
            }

            $this->breadcrumbBuilder->addSimpleItem(ucfirst($this->translator->trans($breadcrumb['label'])), $uri);
        }

        $form = $this->getFormForId($id);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $command = $form->getData();
            $this->handler->handle($command);

            $this->flashBag->add(
                'success',
                $this->translator->trans(
                    $id === null ? 'sumocoders.multiuserbundle.flash.added' : 'sumocoders.multiuserbundle.flash.edited',
                    ['%user%' => $command->getEntity()->getDisplayName()]
                )
            );

            if ($this->redirectRoute !== null) {
                return new RedirectResponse($this->router->generate($this->redirectRoute));
            }
        }

        if ($id !== null) {
            $deleteForm = $this->formFactory->create(DeleteType::class, $form->getData());

            return [
                'form' => $form->createView(),
                'deleteForm' => $deleteForm->createView(),
                'user' => $form->getData()->getEntity(),
            ];
        }

        return ['form' => $form->createView()];
    }
1096764
public function putAction(Request $request, $id)
    {
        $this->checkAccess('PUT', $id);
        $resource = $this->getResourceManager()->find($id);
        return $this->processPut($request, $resource);
    }
1235300
public function formAction($id, Request $request)
    {
        $data = $this->resolveData($id);
        $form = $this->buildForm($data);

        $breadcrumbs = $this->buildBreadcrumbs($this->getType());
        if (!$data->getId()) {
            $breadcrumbs->addItem('navigation.new');
        } else {
            $breadcrumbs->addItem($this->resolveDataTitle($data));
        }

        $form->handleRequest($request);

        if ($form->isValid()) {
            $data = $form->getData();
            $this->persistData($form);

            $request->getSession()
                ->getFlashBag()
                ->add('success', 'Your changes were saved!');

            return $this->redirect($this->getFormSuccessUrl($data));
        }

        $module = $this->getModule($this->getType());

        return $this->render('ClasticNodeBundle:Backoffice/Node:form.html.twig', array(
            'form' => $form->createView(),
            'module' => $module,
            'submodules' => $this->getSubmodules($module),
        ));
    }