Sonata\CustomerBundle\Controller\CustomerController::updateAddress PHP Method

updateAddress() protected method

Updates or create an address.
protected updateAddress ( integer $id = null ) : RedirectResponse | Response
$id integer Address id
return Symfony\Component\HttpFoundation\RedirectResponse | Symfony\Component\HttpFoundation\Response
    protected function updateAddress($id = null)
    {
        $customer = $this->getCustomer();
        // Show address creation/edition form
        if (null === $id) {
            $form = $this->createForm('sonata_customer_address');
        } else {
            $address = $this->getAddressManager()->findOneBy(array('id' => $id));
            $this->checkAddress($address);
            $form = $this->createForm('sonata_customer_address', $address, array('context' => $this->getRequest()->query->get('context')));
        }
        $template = 'SonataCustomerBundle:Addresses:new.html.twig';
        if ($this->get('request')->getMethod() == 'POST') {
            $form->bind($this->get('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, array('form' => $form->createView(), 'breadcrumb_context' => 'customer_address'));
    }