public function updateAction(Request $request, AbstractAdmin $admin)
    {
        $translator = $this->getTranslator();

        $id = $request->attributes->get('id');
        $entity = $this->getDoctrine()->getRepository($admin->getEntityClass())->find($id);

        if (!$entity) {
            throw $this->createNotFoundException('That resource cannot be found');
        }

        $this->secure($admin, ContentVoter::UPDATE_CONTENT, $entity);

        $form = $this->getUpdateForm($admin, $entity);

        $form->handleRequest($request);
        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $admin->preUpdate($entity);
            $em->persist($entity);
            $admin->postUpdate($entity);
            $em->flush();

            $this->get('session')->getFlashBag()->add('success', $translator->trans('crud.edit.success', [], 'ShuweeAdminBundle'));

            return $this->redirect($this->getAdminRoutingHelper()->generateUrl($admin, 'index'));
        }

        return $this->render(
            'ShuweeAdminBundle:Content:update.html.twig',
            [
                'admin' => $admin,
                'entity' => $entity,
                'form' => $form->createView(),
            ]
        );
    }
public function updateAction(Request $request, AbstractAdmin $admin)
    {
        $translator = $this->getTranslator();

        $id = $request->attributes->get('id');
        $entity = $this->getDoctrine()->getRepository($admin->getEntityClass())->find($id);

        if (!$entity) {
            throw $this->createNotFoundException('That resource cannot be found');
        }

        $this->secure($admin, ContentVoter::UPDATE_CONTENT, $entity);

        $form = $this->getUpdateForm($admin, $entity);

        $form->handleRequest($request);
        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $admin->preUpdate($entity);
            $em->persist($entity);
            $admin->postUpdate($entity);
            $em->flush();

            $this->get('session')->getFlashBag()->add('success', $translator->trans('crud.edit.success', [], 'ShuweeAdminBundle'));

            return $this->redirect($this->getAdminRoutingHelper()->generateUrl($admin, 'index'));
        }

        return $this->render(
            'ShuweeAdminBundle:Content:update.html.twig',
            [
                'admin' => $admin,
                'entity' => $entity,
                'form' => $form->createView(),
            ]
        );
    }
public function updateAction ( Request $ request , AbstractAdmin $ admin ) { $ translator = $ this -> getTranslator ( ) ; $ id = $ request -> attributes -> get ( 'id' ) ; $ entity = $ this -> getDoctrine ( ) -> getRepository ( $ admin -> getEntityClass ( ) ) -> find ( $ id ) ; if ( ! $ entity ) { throw $ this -> createNotFoundException ( 'That resource cannot be found' ) ; } $ this -> secure ( $ admin , ContentVoter :: UPDATE_CONTENT , $ entity ) ; $ form = $ this -> getUpdateForm ( $ admin , $ entity ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ admin -> preUpdate ( $ entity ) ; $ em -> persist ( $ entity ) ; $ admin -> postUpdate ( $ entity ) ; $ em -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , $ translator -> trans ( 'crud.edit.success' , [ ] , 'ShuweeAdminBundle' ) ) ; return $ this -> redirect ( $ this -> getAdminRoutingHelper ( ) -> generateUrl ( $ admin , 'index' ) ) ; } return $ this -> render ( 'ShuweeAdminBundle:Content:update.html.twig' , [ 'admin' => $ admin , 'entity' => $ entity , 'form' => $ form -> createView ( ) , ] ) ; }
Update a given entity

@throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the resource cannot be loaded

@param \Symfony\Component\HttpFoundation\Request $request
@param \Wanjee\Shuwee\AdminBundle\Admin\AbstractAdmin $admin
@return \Symfony\Component\HttpFoundation\Response
Update a given entity