Write an address, this method is used by both POST and PUT action methods.

@param Request  $request Symfony request
@param int|null $id      An Address identifier

@return \FOS\RestBundle\View\View|FormInterface
422042
protected function handleWriteAddress($request, $id = null)
    {
        $address = $id ? $this->getAddress($id) : null;

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

        $form->handleRequest($request);

        if ($form->isValid()) {
            $address = $form->getData();
            $this->addressManager->save($address);

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

            // simplify when dropping FOSRest < 2.1
            if (method_exists($context, 'enableMaxDepth')) {
                $context->enableMaxDepth();
            } else {
                $context->setMaxDepth(10);
            }

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

            return $view;
        }

        return $form;
    }
57145
protected function handleWriteCategory($request, $id = null)
    {
        $category = $id ? $this->getCategory($id) : null;

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

        FormHelper::removeFields($request->request->all(), $form);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $category = $form->getData();
            $this->categoryManager->save($category);

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

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

            return $view;
        }

        return $form;
    }
29415
protected function updateAddress($id = null)
    {
        $request = $this->getCurrentRequest();
        $customer = $this->getCustomer();

        // Show address creation/edition form
        if (null === $id) {
            $form = $this->createForm(AddressType::class);
        } else {
            $address = $this->getAddressManager()->findOneBy(['id' => $id]);
            $this->checkAddress($address);

            $form = $this->createForm(AddressType::class, $address, [
                'context' => $request->query->get('context'),
            ]);
        }

        $template = 'SonataCustomerBundle:Addresses:new.html.twig';

        if ('POST' === $request->getMethod()) {
            $form->handleRequest($request);

            if ($form->isValid()) {
                $address = $form->getData();

                $customer->addAddress($address);

                $this->getCustomerManager()->save($customer);

                $this->get('session')->getFlashBag()->add('sonata_customer_success', $id ? 'address_edit_success' : 'address_add_success');

                $url = $this->get('session')->get('sonata_address_redirect', $this->generateUrl('sonata_customer_addresses'));

                return new RedirectResponse($url);
            }
        }

        return $this->render($template, [
            'form' => $form->createView(),
            'breadcrumb_context' => 'customer_address',
        ]);
    }
573664
protected function handleWriteCollection($request, $id = null)
    {
        $collection = $id ? $this->getCollection($id) : null;

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

        FormHelper::removeFields($request->request->all(), $form);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $collection = $form->getData();
            $this->collectionManager->save($collection);

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

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

            return $view;
        }

        return $form;
    }
301226
public function update(Request $request, $id)
    {
        $rules = [
            "address" => "required|max:256",
            "country" => "required",
            "label" => "required|max:50",
            "municipality" => "required|max:128",
            "postcode" => 'required|regex:/^[0-9]{5}(-\d{4})?$/',
            "stateProvince" => "required",
        ];
        /** @noinspection PhpUndefinedMethodInspection */
        $request->validate($this->addPolymorphicRules($rules, 'addressable', $request->addressableType));
        $address = Address::findOrFail($id);
        $this->authorize('manage', $address);
        $address->label = $request->label;
        $address->address = $request->address;
        $address->municipality = $request->municipality;
        $address->state_province = $request->stateProvince;
        $address->postcode = $request->postcode;
        $address->country = $request->country;
        $address->save();
        return fractal($address, new AddressTransformer())
            ->withResourceName('address')
            ->respond();
    }
77903
public function editAction(Request $request, $id)
    {
        $em = $this->getDoctrine()->getManager();
        $site = $em->getRepository(Site::class)->find($id);

        $originalDomains = new ArrayCollection();
        foreach ($site->getDomains() as $domain) {
            $originalDomains->add($domain);
        }

        $form = $this->createForm(SiteType::class, $site);
        $form->handleRequest($request);


        if ($form->isSubmitted() && $form->isValid()) {

            // Remove deleted domains
            foreach ($originalDomains as $domain) {
                if (false === $site->getDomains()->contains($domain)) {
                    $em->remove($domain);
                }
            }

            // Add new domain
            foreach ($form->getData()->getDomains() as $domain) {
                $domain->setSite($site);
            }
            $em->persist($domain);

            $em->flush();

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

        return $this->render('OpiferCmsBundle:Backend/Site:edit.html.twig', [
            'form' => $form->createView(),
            'site' => $site,
        ]);
    }
405733
public function schemaAction(Request $request, $id = null)
    {
        $request->attributes->set('schemaRequest', true);

        list($app, $module, , $modelName, $schemaType) = explode('.', $request->attributes->get('_route'));

        $response = $this->response;
        $response->setStatusCode(Response::HTTP_OK);
        $response->setVary(['Origin', 'Accept-Encoding']);
        $response->setPublic();

        if (!$id && $schemaType != 'canonicalIdSchema') {
            $schema = $this->schemaUtils->getCollectionSchema($modelName, $this->getModel());
        } else {
            $schema = $this->schemaUtils->getModelSchema($modelName, $this->getModel());
        }

        // enabled methods for CorsListener
        $corsMethods = 'GET, POST, PUT, PATCH, DELETE, OPTIONS';
        try {
            $router = $this->getRouter();
            // if post route is available we assume everything is readable
            $router->generate(implode('.', array($app, $module, 'rest', $modelName, 'post')));
        } catch (RouteNotFoundException $exception) {
            // only allow read methods
            $corsMethods = 'GET, OPTIONS';
        }

        $request->attributes->set('corsMethods', $corsMethods);
        $response->setContent($this->restUtils->serialize($schema));

        return $response;
    }
466579
public function getAction(Request $request, $id)
    {
        if (null !== $request->get('fields')) {
            return $this->getContent($request, $id);
        }

        return $this->getSingleNode($request, $id);
    }
1161017
protected function handleWriteContext($request, $id = null)
    {
        $context = $id ? $this->getContext($id) : null;

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

        FormHelper::removeFields($request->request->all(), $form);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $context = $form->getData();
            $this->contextManager->save($context);

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

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

            return $view;
        }

        return $form;
    }
180026
public function update($id,Request $request)
    {
        $setting = Setting::findOrfail($id);
    	
        $setting->name = $request->name;
        
        $setting->description = $request->description;
        
        
        $setting->save();

        return redirect('setting');
    }
192339
public function putAction($id, Request $request)
    {
        $response = $this->getResponse();
        $model = $this->getModel();

        $this->restUtils->checkJsonRequest($request, $response, $this->getModel());
        $record = $this->restUtils->validateRequest($request->getContent(), $model);

        // handle missing 'id' field in input to a PUT operation
        // if it is settable on the document, let's set it and move on.. if not, inform the user..
        if ($record->getId() != $id) {
            // try to set it..
            if (is_callable(array($record, 'setId'))) {
                $record->setId($id);
            } else {
                throw new MalformedInputException('No ID was supplied in the request payload.');
            }
        }

        // And update the record, if everything is ok
        if (!$this->getModel()->recordExists($id)) {
            $this->getModel()->insertRecord($record, false);
        } else {
            $this->getModel()->updateRecord($id, $record, false);
        }

        // Set status code
        $response->setStatusCode(Response::HTTP_NO_CONTENT);

        // store id of new record so we dont need to reparse body later when needed
        $request->attributes->set('id', $record->getId());

        return $response;
    }
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()];
    }
1132373
public function putAction(Request $request, $id)
    {
        $locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));

        try {
            $attribute = $this->getManager()->save(
                $request->request->all(),
                $locale,
                $this->getUser()->getId(),
                $id
            );
            $view = $this->view($attribute, 200);
        } catch (AttributeDependencyNotFoundException $exc) {
            $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
            $view = $this->view($exception->toArray(), 400);
        } catch (AttributeNotFoundException $exc) {
            $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
            $view = $this->view($exception->toArray(), 404);
        } catch (MissingAttributeException $exc) {
            $exception = new MissingArgumentException(self::$entityName, $exc->getAttribute());
            $view = $this->view($exception->toArray(), 400);
        }

        return $this->handleView($view);
    }
1256113
public function handleEdit(int $id = null, array $request = [])
    {
        if ($id === null) {
            if (isset($_GET['template']) === false) {
                return redirect($this->router->generate('pages-list-page') . "?m=2");
            } else {
                return 'Redirect: ' . $this->router->generate('pages-list-page') . "?m=2";
            }
        }
        $page = $this->core->api('Page/' . $id, 'GET')->run();
        if ($page['headers'][0][2] === 422) {
            if (isset($_GET['template']) === false) {
                return redirect($this->router->generate('pages-list-page') . "?m=2");
            } else {
                return 'Redirect: ' . $this->router->generate('pages-list-page') . "?m=2";
            }
        } elseif (($page["headers"][0][2] - 200) * ($page["headers"][0][2] - 299) > 0) {
            if (headers_sent() === false) {
                foreach ($page["headers"] as $header) {
                    header($header[0], $header[1], $header[2]);
                }
            }
            return $this->templates->render("500", [
                "error" => $page['response'],
                "result" => ''
            ]);
        }
        $page = $page['response'];

        if (isset($request['byline']) === true && $request['byline'] === '') {
            unset($request['byline']);
        }
        if (isset($request['link']) === true && $request['link'] === '') {
            unset($request['link']);
        }
        if (isset($request['content']) === true && $request['content'] === '') {
            unset($request['content']);
        }
        if (isset($request['featured']) === true && $request['featured'] === '') {
            unset($request['featured']);
        }
        if (isset($request['tags']) === true && $request['tags'] === '') {
            unset($request['tags']);
        }
        if (isset($request['class']) === true && $request['class'] === '') {
            unset($request['class']);
        }
        if (isset($request['page_id']) === true && $request['page_id'] === '') {
            unset($request['page_id']);
        }
        $validator = new \Valitron\Validator($request);
        $validator->rule('required', ['title']);
        $validator->rule('optional', ['byline', 'content', 'link', 'tags', 'class', 'featured', 'page_id']);
        $validator->rule(function ($field, $value, array $params, array $fields) {
            return is_string($value);
        }, ['title', 'byline', 'content'])->message("{field} must be a string");
        $validator->rule(function ($field, $value, array $params, array $fields) {
            return file_exists(rtrim(public_path(), '/') . $value) || (filter_var($value, FILTER_VALIDATE_URL) !== false);
        }, 'featured')->message("{field} must be an external link or a local file path");
        $validator->rule(function ($field, $value, $params, $fields) {
            if (is_array($value) === true || preg_match('/[\w\-]+(,\s?[\w\-]+)*/', $value) === 1) {
                return true;
            }
            return false;
        }, ["tags", "class"])->message("{field} must be an array or comma-separated");
        $validator->rule(function ($field, $value, $params, $fields) {
            $page = Model\Page::find($value);
            if ($page === null) {
                return false;
            }
            return true;
        }, "page_id")->message("{field} must be child of a valid page");
        $validator->rule(function ($field, $value, $params, $fields) {
            $page = Model\Page::where('link', $value)->first();
            if ($page === null) {
                return true;
            }
            return false;
        }, "link")->message("{field} must be unique");
        if ($validator->validate() === false) {
            if (headers_sent() === false) {
                header('X-PHP-Response-Code: 422', true, 422);
            }
            $page = $this->core->api('Page/' . $id, 'GET')->run();
            $pages_list = $this->core->api('Page/all', 'GET')->run();
            return $this->templates->render("Main::Pages/Edit", [
                "messages" => [
                    'error' => $validator->errors(),
                    'info' => '',
                    'success' => '',
                    'warning' => ''
                ],
                "page" => $page['response'],
                "pages" => $pages_list['response']
            ]);
        }

        $response = [];
        if (empty($request['publish']) === false) {
            $request['status'] = 1;
            $response = $this->core->api('Page/' . $page->id, 'PUT')->run($request);
        } elseif (empty($request['draft']) === false) {
            $request['status'] = 0;
            $response = $this->core->api('Page/' . $page->id, 'PUT')->run($request);
        }

        if (headers_sent() === false) {
            foreach ($response["headers"] as $header) {
                header($header[0], $header[1], $header[2]);
            }
        }
        if ($response["headers"][0][2] === 422) {
            $page = $this->core->api('Page/' . $id, 'GET')->run();
            $pages_list = $this->core->api('Page/all', 'GET')->run();
            return $this->templates->render("Main::Pages/Edit", [
                "messages" => [
                    'error' => $response['response'],
                    'info' => '',
                    'success' => '',
                    'warning' => ''
                ],
                "page" => $page['response'],
                "pages" => $pages_list['response']
            ]);
        } elseif (($response["headers"][0][2] - 200) * ($response["headers"][0][2] - 299) <= 0) {
            $page = $this->core->api('Page/' . $id, 'GET')->run();
            $pages_list = $this->core->api('Page/all', 'GET')->run();
            return $this->templates->render("Main::Pages/Edit", [
                "messages" => [
                    'error' => '',
                    'info' => '',
                    'success' => 'Page updated successfully.',
                    'warning' => ''
                ],
                "page" => $page['response'],
                "pages" => $pages_list['response']
            ]);
        } else {
            return $this->templates->render("500", [
                "error" => $response['response'],
                "result" => ''
            ]);
        }
    }
286613
public function editDeliveryAction(Request $request, $id)
    {
        if($request->isXmlHttpRequest()){
            $em = $this->container->get('doctrine')->getManager();
            $user = $this->container->get('security.token_storage')->getToken()->getUser();
        
            /** @var Address $address */
            $address = $em->getRepository('EcommerceBundle:Address')->findOneBy(array(
                    'id'   => $id,
                    'actor' => $user,
                ));
            $form = $this->createForm('EcommerceBundle\Form\AddressType', $address, array('token_storage' => $this->container->get('security.token_storage')));

            if ('POST' === $request->getMethod()) {
                $form->handleRequest($request);

                if ($form->isValid()) {
                    $em->persist($address);
                    $em->flush();
                    $url = $this->container->get('router')->generate('core_actor_profile').'?delivery=1';
                    $this->container->get('session')->getFlashBag()->add('success', 'account.address.saved');
                    return new JsonResponse(array('status' => 'success', 'url' => $url));
                }else{
                    $template = $this->container->get('twig')->render("EcommerceBundle:Profile:Delivery/edit.html.twig", array(
                        'delivery_form' => $form->createView(),
                        'address' => $address
                    ));
                    return new JsonResponse(array('status' => 'error', 'answer' => $template));
                }
            }
        }else {
            throw new \Exception('Only by ajax');
        }
    }
560696
public function editAction(Request $request, $id)
    {
        $mailingList = $this->getDoctrine()->getRepository('OpiferMailingListBundle:MailingList')->find($id);

        $form = $this->createForm(MailingListType::class, $mailingList);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->flush();

            return $this->redirectToRoute('opifer_mailing_list_mailing_list_index');
        }

        return $this->render('OpiferMailingListBundle:MailingList:edit.html.twig', [
            'form' => $form->createView(),
            'mailing_list' => $mailingList,
        ]);
    }
964149
public function update(Request $request, $id = null)
    {
        try {
            $application = $this->applications->save($request, $id);
            if ($request->has('theme')) {
                \Cookie::queue('soda-theme', $request->input('theme'));
                $request->session()->put('soda-theme', $request->input('theme'));
            }
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.update', ['object' => 'application']));
        }

        return redirect()->route('soda.settings.edit', $application->getKey())->with('success', trans('soda::messages.updated', ['object' => 'application']));
    }