public function editAction($id, Request $request, $source)
{
$address = $this->get('elcodi.repository.customer')->findAddress($this->getUser()->getId(), $id);
if (!$address instanceof AddressInterface) {
throw new NotFoundHttpException('Address not found');
}
$form = $this->createForm('store_geo_form_type_address', $address);
$form->handleRequest($request);
if ($form->isValid()) {
$addressToSave = $this->get('elcodi.manager.address')->saveAddress($address);
$customer = $this->getUser();
$customer->removeAddress($address);
$customer->addAddress($addressToSave);
$this->get('elcodi.object_manager.customer')->flush($customer);
$message = $this->get('translator')->trans('store.address.save.response_ok');
$this->addFlash('success', $message);
$redirectUrl = self::CHECKOUT_SOURCE == $source ? 'store_checkout_address' : 'store_address_list';
return $this->redirect($this->generateUrl($redirectUrl));
} else {
$this->get('elcodi.object_manager.address')->clear($address);
}
return $this->renderTemplate('Pages:address-edit.html.twig', ['address' => $address, 'form' => $form->createView()]);
}