edit

@author Tom Haskins-Vaughan <tom@tomhv.uk>
@since  0.8.0

@Template
@ParamConverter("journal", class="Phospr\CoreBundle\Entity\Journal")

@param  Request $request
@param  Journal $journal
546215
public function editAction(Request $request, Journal $journal)
    {
        // Let's add a blank posting
        $journal->addPosting(
            $this->get('phospr.posting_handler')->createPosting()
        );

        $form = $this->createForm('journal', $journal);
        $form->handleRequest($request);

        if ($form->isValid()) {
            try {
                foreach ($form->getData()->getPostings() as $posting) {
                    if (!$posting->getAccount()) {
                        $form->getData()->removePosting($posting);
                    }
                }

                $em = $this->get('doctrine')->getManager();
                $em->persist($form->getData());
                $em->flush();

                return $this->redirect($this->generateUrl(
                    'phospr_journal_show', array('id' => $journal->getId())
                ));
            } catch (JournalImbalanceException $e) {
                exit($e->getMessage());
            }
        }

        return array(
            'journal' => $journal,
            'form' => $form->createView(),
        );
    }
171847
public function updateAction(Request $request)
        {

            /** @var License $oLicense */
            $oLicense = LicenseQuery::create()->findOne();

            if ($oLicense === null) {
                throw $this->createNotFoundException('Unable to find License entity.');
            }

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

            $aResult = array(
                "success" => false,
                "message" => ""
            );

            $sLico = SystemSettings::get("lico");

            $aHeaders = array(
                'Content-Type: application/json'
            );

            $sDomain = $this->_getSiteURL();

            $aRequest = array(
                'lico' => array(
                    'domain'  => $sDomain,
                    'license' => $oLicense->getSerial()
                ),
            );

            $sRequest = json_encode($aRequest);

            /*
             * Check license against license-server
             */
            $oRequest = curl_init($sLico . "/api/check/license");
            curl_setopt($oRequest, CURLOPT_HTTPHEADER, $aHeaders);
            curl_setopt($oRequest, CURLOPT_TIMEOUT, 120);
            curl_setopt($oRequest, CURLOPT_POST, 1);
            curl_setopt($oRequest, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($oRequest, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($oRequest, CURLOPT_POSTFIELDS, $sRequest);
            curl_setopt($oRequest, CURLOPT_RETURNTRANSFER, true);
            $response    = curl_exec($oRequest);
            $iHttpStatus = curl_getinfo($oRequest, CURLINFO_HTTP_CODE);
            $error       = curl_error($oRequest);
            curl_close($oRequest);

            if ($iHttpStatus == 200) {

                $oResponse = json_decode($response);

                if ($editForm->isValid() && $oResponse->valid == true) {
                    $aResult['max_clients'] = $oResponse->max_clients;
                    $aResult['valid_until'] = $oResponse->valid_until;
                    $aResult['domain']      = $sDomain;

                    $aResult['success'] = true;
                    $aResult['message'] = $this->get("translator")->trans("license.update.successful");

                    // license valid, save new license-data
                    $oLicense->setValidUntil($aResult['valid_until']);
                    $oLicense->setMaxClients($aResult['max_clients']);
                    $oLicense->setDomain($sDomain);
                    $oLicense->save();
                } else {
                    $aResult['success'] = false;
                    $aResult['message'] = $this->get("translator")->trans("license.update.failed");
                    $aResult['valid_until'] = strtotime("1970-01-01");
                    $aResult['max_clients'] = 0;
                    $aResult['domain'] = "-";
                }


            } else {

                $aResult['max_clients'] = $oLicense->getMaxClients();
                $aResult['valid_until'] = strtotime($oLicense->getValidUntil());
                $aResult['domain']      = $sDomain;

                $aResult['success'] = false;
                $aResult['message'] = $this->get("translator")->trans("license.update.failed_lico");
            }


            $sResult  = json_encode($aResult);
            $response = new Response($sResult);
            $response->headers->set('Content-Type', 'application/json');

            return $response;
        }
78190
public function editBlockAction(Request $request, $id, $version = 0)
    {
        $this->getDoctrine()->getManager()->getFilters()->disable('draftversion');

        /** @var BlockManager $manager */
        $manager = $this->get('opifer.content.block_manager');
        $version = $manager->getNewVersion($manager->find($id));

//        if ((int) $rootVersion !== $newVersion) {
//            throw new \Exception("Only new versions can be editted. New version is {$newVersion} while you requested {$rootVersion}");
//        }

        $block = $manager->find($id, $version);

        /** @var BlockServiceInterface $service */
        $service = $manager->getService($block);
        $block->setRootVersion($version);

        $updatePreview = false; // signals parent window preview from iframe to update preview

        $service->preFormSubmit($block);

        $form = $this->createForm(new BlockAdapterFormType($service), $block);
        $form->handleRequest($request);

        if ($form->isValid()) {

            $service->postFormSubmit($form, $block);

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

        return $this->render($service->getEditView(), [
            'block_service' => $service,
            'block' => $block,
            'form' => $form->createView(),
            'update_preview' => $updatePreview
        ]);
    }
334046
public function edit(Request $request)
    {
        $countries = collect(countries())->map(function ($country, $code) {
            return [
                'id' => $code,
                'text' => $country['name'],
                'emoji' => $country['emoji'],
            ];
        })->values();
        $languages = collect(languages())->pluck('name', 'iso_639_1');
        $genders = ['male' => trans('cortex/auth::common.male'), 'female' => trans('cortex/auth::common.female')];

        return view('cortex/auth::adminarea.pages.account-settings', compact('countries', 'languages', 'genders'));
    }
330729
public function update(Request $request) {

	    // Grab these inputs to determine if we need to return to the edit form after updating
        $return_to_edit = $request->input('return_to_edit');
        $record_id      = $request->input('id');

        // Launch the command, and capture the results (I should refactor "$response", but have not yet!)
        $response = $this->dispatchFrom(UpdateBaseCommand::class, $request);

        Session::flash('status_code', $response['status_code'] );


        ///////////////////////////////////////////////////////////////
        //              Problems with the update                     //
        ///////////////////////////////////////////////////////////////
        //        Session::flash('message', $message);

        if ($response['status_text'] == "validation_failed")
        {
            // flash message
            if (is_object($response['errorMessages'])) {
                Session::flash('message', $response['errorMessages']->first());
            } else {
                Session::flash('message', $response['errorMessages']);
            }

            // Return to the edit form with error messages
            return Redirect::back()
                ->withInput($response['data'])
                ->withErrors($response['errorMessages']);
        }


        if ($response['status_text'] == "persist_failed")
        {
            $message = "Persist failed. It does not happen often, but Laravel's save failed. The database operation is called at Lasallecms\Lasallecmsapi\\".$this->model->table."\\".$this->model->classname_formprocessor_delete.". MySQL probably hiccupped, so probably just try again.";

            Session::flash('message', $message);

            // Return to the edit form with error messages
            return Redirect::back()
                ->withInput($response['data']);
        }



        ///////////////////////////////////////////////////////////////
        //                  Update Succeeded!                        //
        ///////////////////////////////////////////////////////////////

        if ( empty($response['data']['title']) ) {
             $response['data']['title'] = strtoupper($response['data']['composite_title']);
        }

        ///////////////////////////////////////////////////////////////
        //                     Event?                                //
        ///////////////////////////////////////////////////////////////

        // if there is an event to fire where need to show an "are you sure" confirmation first
        if ($response['status_text'] == "update_successful_now_confirm_before_firing_event") {

            $message =  "You successfully updated the ".strtolower($this->model->model_class)." ".strtoupper($response['data']['title'])."!";

            Session::flash('message', $message);

            return view('lasallecrmlistmanagement::confirmations.confirm_send_to_list', [
                'user'                 => Auth::user(),
                'data'                 => $response['data'],
                'message'              => $message,
                'HTMLHelper'           => HTMLHelper::class,
            ]);
        }

        // if there is an event to fire with *no* "are you sure" confirmation first
        if ($response['status_text'] == "update_successful_with_event_fired") {

            $message =  "You successfully updated the ".strtolower($this->model->model_class)." ".strtoupper($response['data']['title'])." *and* ".$response['data']['eventDescription']."!";

            Session::flash('message', $message);
        }

        ///////////////////////////////////////////////////////////////
        //                     Redirect                              //
        ///////////////////////////////////////////////////////////////

        // Redirect to the edit form?
        if ($return_to_edit == "Save & Edit") {
            return Redirect::route('admin.'.$this->model->resource_route_name.'.edit', $record_id);
        }

        return Redirect::route('admin.'.$this->model->resource_route_name.'.index');
    }
681572
public function edit($request) {
        $controller=$this->getToplevelController();
        $form=$this->ItemEditForm($this->gridField, $request);
        
        
        return $controller->customise(array(
                                    'Title'=>($this->record && $this->record->ID ? $this->record->Title:sprintf(_t('GridField.NewRecord', 'New %s'), $this->record->i18n_singular_name())),
                                    'ItemEditForm'=>$form,
                                ))->renderWith($this->template);
    }
1347892
public function add(Request $request, $table)
    {
        Admin::canOrFail('browse_database');

        $data = $this->prepopulateInfo($table);
        $data['fieldOptions'] = SchemaManager::describeTable($table);

        return Admin::view('admin::tools.database.edit-add-crud', $data);
    }
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(),
        ]);
    }
779302
public function editAction(Request $request, ContentTypePage $page)
    {
        $form = $this->createEditForm($page);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $channel = $this->getSelectedChannel();

            $this->getDocumentManager()->flush();

            $this->get('integrated_page.services.route_cache')->clear();

            $this->get('braincrafted_bootstrap.flash')->success('Page updated');

            return $this->redirectToRoute('integrated_page_content_type_page_index', ['channel' => $channel->getId()]);
        }

        return [
            'page' => $page,
            'form' => $form->createView(),
        ];
    }
658429
public function postGenerateAction(Request $request)
    {
        $parentUuid = $this->getRequestParameter($request, 'parent');
        $parts = $this->getRequestParameter($request, 'parts', true);
        $templateKey = $this->getRequestParameter($request, 'template', true);
        $webspaceKey = $this->getRequestParameter($request, 'webspace', true);
        $languageCode = $this->getLocale($request);

        $result = $this->getResourceLocatorRepository()->generate(
            $parts,
            $parentUuid,
            $webspaceKey,
            $languageCode,
            $templateKey
        );

        return $this->handleView($this->view($result));
    }
1099744
public function edit(Request $request, $key)
    {
        if ($request->wantsJson()) {
            return $this->validNotFoundJsonResponse();
        }

        $model = $this->findFirstByKey($key);

        if (!$model) {
            abort(404);
        }

        $view = $this->getViewLocation(__FUNCTION__);
        $this->checkViewExists($view);

        return response()->view($view, compact('model'));
    }
755185
public function editAction(Request $request, $episode)
    {
        $entity = $episode;

        $editForm = $this->createEditForm($entity);
        $deleteForm = $this->createDeleteForm($id);

        return [
            'entity' => $entity,
            'form' => $editForm->createView(),
            'delete_form' => $deleteForm->createView(),
        ];
    }
402787
public function editAction(Request $request, $type, $alias)
    {
        $this->performAccessChecks();

        $value = $request->get('value');

        $response = new Response();

        try {
            $this->cronService->updateCron($alias, $type, $value);
            $response->setStatusCode(
                200,
                $this->translator->trans('cron.edit.done', ['%type%' => $type, '%alias%' => $alias], 'smileezcron')
            );
        } catch (NotFoundException $e) {
            $response->setStatusCode(500, $e->getMessage());
        } catch (InvalidArgumentException $e) {
            $response->setStatusCode(500, $e->getMessage());
        }

        return $response;
    }
230829
public function removeTranslationAction(Request $request): Response
    {
        $form = $this->contentTypeFormFactory->removeContentTypeTranslation(
            new TranslationRemoveData()
        );
        $form->handleRequest($request);

        /** @var TranslationRemoveData $data */
        $data = $form->getData();
        $contentType = $data->getContentType();
        $contentTypeGroup = $data->getContentTypeGroup();

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (TranslationRemoveData $data) {
                $contentType = $data->getContentType();
                $languageCodes = $data->getLanguageCodes();
                $contentTypeGroup = $data->getContentTypeGroup();
                try {
                    $contentTypeDraft = $this->tryToCreateContentTypeDraft($contentType);
                } catch (BadStateException $e) {
                    $userId = $contentType->modifierId;
                    $this->notificationHandler->error(
                        $this->translator->trans(
                            /** @Desc("Draft of the Content Type '%name%' already exists and is locked by '%userContentName%'") */
                            'content_type.edit.error.already_exists',
                            ['%name%' => $contentType->getName(), '%userContentName%' => $this->getUserNameById($userId)],
                            'content_type'
                        )
                    );

                    return $this->redirectToRoute('ezplatform.content_type.view', [
                        'contentTypeGroupId' => $contentTypeGroup->id,
                        'contentTypeId' => $contentType->id,
                    ]);
                }
                foreach ($languageCodes as $languageCode => $isChecked) {
                    $newContentTypeDraft = $this->contentTypeService->removeContentTypeTranslation($contentTypeDraft, $languageCode);
                }
                $this->contentTypeService->publishContentTypeDraft($newContentTypeDraft);

                return new RedirectResponse($this->generateUrl('ezplatform.content_type.view', [
                    'contentTypeId' => $contentType->id,
                    'contentTypeGroupId' => $contentTypeGroup->id,
                    '_fragment' => TranslationsTab::URI_FRAGMENT,
                ]));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->redirectToRoute('ezplatform.content_type.view', [
            'contentTypeGroupId' => $contentTypeGroup->id,
            'contentTypeId' => $contentType->id,
        ]);
    }
688612
public function editAction(Request $request, $id = null)
    {
        $this->denyAccessUnlessGranted('ROLE_ADMIN');

        $em = $this->getDoctrine()->getManager();

        if (is_numeric($id)) {
            $locale = $em->getRepository(Locale::class)->find($id);
        } else {
            $locale = $em->getRepository(Locale::class)->findOneByLocale($id);
        }

        $form = $this->createForm(new LocaleType(), $locale);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em->persist($locale);
            $em->flush();

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

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

        return $this->render('OpiferCmsBundle:Backend/Locale:edit.html.twig', [
            'locale' => $locale,
            'form' => $form->createView()
        ]);
    }
1027362
public function edit(Request $request, $id)
    {
        $view = parent::edit($request, $id);

        $view['layouts'] = Layouts::getLayouts('voyager-frontend');

        return $view;
    }
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(),
        ));
    }