Controller/AddressController.php
public function editAction(Request $request)
    {
        $user = $this->getUser();
        $repository = $this->get('ekyna_user.address.repository');

        if (null === $address = $repository->find($request->attributes->get('addressId'))) {
            throw new NotFoundHttpException('Address not found.');
        }
        if ($address->getUser()->getId() !== $user->getId()) {
            throw new AccessDeniedHttpException('Access denied');
        }

        $cancelPath = $this->generateUrl('ekyna_user_address_list');

        /** @var \Symfony\Component\Form\FormInterface $form */
        $form = $this
            ->createForm('ekyna_user_address', $address, [
                '_redirect_enabled' => true,
            ])
            ->add('actions', 'form_actions', [
                'buttons' => [
                    'save' => [
                        'type' => 'submit', 'options' => [
                            'button_class' => 'primary',
                            'label' => 'ekyna_core.button.save',
                            'attr' => [
                                'icon' => 'ok',
                            ],
                        ],
                    ],
                    'cancel' => [
                        'type' => 'button', 'options' => [
                            'label' => 'ekyna_core.button.cancel',
                            'button_class' => 'default',
                            'as_link' => true,
                            'attr' => [
                                'class' => 'form-cancel-btn',
                                'icon' => 'remove',
                                'href' => $cancelPath,
                            ],
                        ],
                    ],
                ],
            ])
        ;

        $form->handleRequest($request);
        if ($form->isValid()) {
            $event = $this->get('ekyna_user.address.operator')->update($address);
            if (!$event->isPropagationStopped()) {
                $this->addFlash('ekyna_user.address.message.edit.success', 'success');
                if (null !== $redirectPath = $form->get('_redirect')->getData()) {
                    return $this->redirect($redirectPath);
                }
                return $this->redirect($cancelPath);
            }
            $this->addFlash('ekyna_user.address.message.edit.failure', 'danger');
        }

        return $this->render('EkynaUserBundle:Address:edit.html.twig', [
            'address' => $address,
            'form' => $form->createView()
        ]);
    }
public function editAction(Request $request)
    {
        $user = $this->getUser();
        $repository = $this->get('ekyna_user.address.repository');

        if (null === $address = $repository->find($request->attributes->get('addressId'))) {
            throw new NotFoundHttpException('Address not found.');
        }
        if ($address->getUser()->getId() !== $user->getId()) {
            throw new AccessDeniedHttpException('Access denied');
        }

        $cancelPath = $this->generateUrl('ekyna_user_address_list');

        /** @var \Symfony\Component\Form\FormInterface $form */
        $form = $this
            ->createForm('ekyna_user_address', $address, [
                '_redirect_enabled' => true,
            ])
            ->add('actions', 'form_actions', [
                'buttons' => [
                    'save' => [
                        'type' => 'submit', 'options' => [
                            'button_class' => 'primary',
                            'label' => 'ekyna_core.button.save',
                            'attr' => [
                                'icon' => 'ok',
                            ],
                        ],
                    ],
                    'cancel' => [
                        'type' => 'button', 'options' => [
                            'label' => 'ekyna_core.button.cancel',
                            'button_class' => 'default',
                            'as_link' => true,
                            'attr' => [
                                'class' => 'form-cancel-btn',
                                'icon' => 'remove',
                                'href' => $cancelPath,
                            ],
                        ],
                    ],
                ],
            ])
        ;

        $form->handleRequest($request);
        if ($form->isValid()) {
            $event = $this->get('ekyna_user.address.operator')->update($address);
            if (!$event->isPropagationStopped()) {
                $this->addFlash('ekyna_user.address.message.edit.success', 'success');
                if (null !== $redirectPath = $form->get('_redirect')->getData()) {
                    return $this->redirect($redirectPath);
                }
                return $this->redirect($cancelPath);
            }
            $this->addFlash('ekyna_user.address.message.edit.failure', 'danger');
        }

        return $this->render('EkynaUserBundle:Address:edit.html.twig', [
            'address' => $address,
            'form' => $form->createView()
        ]);
    }
public function editAction ( Request $ request ) { $ user = $ this -> getUser ( ) ; $ repository = $ this -> get ( 'ekyna_user.address.repository' ) ; if ( null === $ address = $ repository -> find ( $ request -> attributes -> get ( 'addressId' ) ) ) { throw new NotFoundHttpException ( 'Address not found.' ) ; } if ( $ address -> getUser ( ) -> getId ( ) !== $ user -> getId ( ) ) { throw new AccessDeniedHttpException ( 'Access denied' ) ; } $ cancelPath = $ this -> generateUrl ( 'ekyna_user_address_list' ) ; /** @var \Symfony\Component\Form\FormInterface $form */ $ form = $ this -> createForm ( 'ekyna_user_address' , $ address , [ '_redirect_enabled' => true , ] ) -> add ( 'actions' , 'form_actions' , [ 'buttons' => [ 'save' => [ 'type' => 'submit' , 'options' => [ 'button_class' => 'primary' , 'label' => 'ekyna_core.button.save' , 'attr' => [ 'icon' => 'ok' , ] , ] , ] , 'cancel' => [ 'type' => 'button' , 'options' => [ 'label' => 'ekyna_core.button.cancel' , 'button_class' => 'default' , 'as_link' => true , 'attr' => [ 'class' => 'form-cancel-btn' , 'icon' => 'remove' , 'href' => $ cancelPath , ] , ] , ] , ] , ] ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ event = $ this -> get ( 'ekyna_user.address.operator' ) -> update ( $ address ) ; if ( ! $ event -> isPropagationStopped ( ) ) { $ this -> addFlash ( 'ekyna_user.address.message.edit.success' , 'success' ) ; if ( null !== $ redirectPath = $ form -> get ( '_redirect' ) -> getData ( ) ) { return $ this -> redirect ( $ redirectPath ) ; } return $ this -> redirect ( $ cancelPath ) ; } $ this -> addFlash ( 'ekyna_user.address.message.edit.failure' , 'danger' ) ; } return $ this -> render ( 'EkynaUserBundle:Address:edit.html.twig' , [ 'address' => $ address , 'form' => $ form -> createView ( ) ] ) ; }
Edit address action.

@param Request $request

@return \Symfony\Component\HttpFoundation\Response

@throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
@throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
Edit address action .