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',
        ]);
    }