Elcodi\Store\GeoBundle\Controller\AddressController::newAction PHP Method

newAction() public method

New address
public newAction ( Elcodi\Component\Geo\Entity\Interfaces\AddressInterface $address, Symfony\Component\Form\FormView $formView, boolean $isValid, string | null $source = null ) : Response
$address Elcodi\Component\Geo\Entity\Interfaces\AddressInterface $address A new address entity
$formView Symfony\Component\Form\FormView The form view
$isValid boolean If the form is valid
$source string | null The form source to redirect back
return Symfony\Component\HttpFoundation\Response Response
    public function newAction(AddressInterface $address, FormView $formView, $isValid, $source = null)
    {
        if ($isValid) {
            $translator = $this->get('translator');
            $addressManager = $this->get('elcodi.object_manager.address');
            $addressManager->persist($address);
            $addressManager->flush();
            $this->get('elcodi.wrapper.customer')->get()->addAddress($address);
            $this->get('elcodi.object_manager.customer')->flush();
            $message = $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));
        }
        return $this->renderTemplate('Pages:address-edit.html.twig', ['address' => $address, 'form' => $formView]);
    }