Controller/PostController.php
public function updateAction(
        string $production_slug,
        int $id,
        Request $request,
        TokenStorageInterface $token,
        AuthorizationCheckerInterface $auth
    ): Response {
        // Lookup the post and production.
        list($post, $production) = $this->lookupEntity(Post::class, $id, $production_slug);

        // Check permissions for this action.
        if (!$auth->isGranted('edit', $post)) {
            throw new AccessDeniedException();
        }

        // Get some basic information about the user.
        $user = $token->getToken()->getUser();

        // Create a new form for the post and handle.
        if (null !== $post->getParent()) {
            $form = $this->form->create(ReplyType::class, $post);
        } else {
            $form = $this->form->create(PostType::class, $post);
        }

        // Handle the form submission.
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            // Flush entity manager, set success message and redirect.
            $this->em->flush();
            $this->session->getFlashBag()->add(
                'success',
                $this->translator->trans('post.updated', [], BkstgNoticeBoardBundle::TRANSLATION_DOMAIN)
            );

            return new RedirectResponse($this->url_generator->generate(
                'bkstg_board_show',
                ['production_slug' => $production->getSlug()]
            ));
        }

        // Render the form.
        return new Response($this->templating->render('@BkstgNoticeBoard/Post/update.html.twig', [
            'form' => $form->createView(),
            'post' => $post,
            'production' => $production,
        ]));
    }
public function updateAction(
        string $production_slug,
        int $id,
        Request $request,
        TokenStorageInterface $token,
        AuthorizationCheckerInterface $auth
    ): Response {
        // Lookup the post and production.
        list($post, $production) = $this->lookupEntity(Post::class, $id, $production_slug);

        // Check permissions for this action.
        if (!$auth->isGranted('edit', $post)) {
            throw new AccessDeniedException();
        }

        // Get some basic information about the user.
        $user = $token->getToken()->getUser();

        // Create a new form for the post and handle.
        if (null !== $post->getParent()) {
            $form = $this->form->create(ReplyType::class, $post);
        } else {
            $form = $this->form->create(PostType::class, $post);
        }

        // Handle the form submission.
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            // Flush entity manager, set success message and redirect.
            $this->em->flush();
            $this->session->getFlashBag()->add(
                'success',
                $this->translator->trans('post.updated', [], BkstgNoticeBoardBundle::TRANSLATION_DOMAIN)
            );

            return new RedirectResponse($this->url_generator->generate(
                'bkstg_board_show',
                ['production_slug' => $production->getSlug()]
            ));
        }

        // Render the form.
        return new Response($this->templating->render('@BkstgNoticeBoard/Post/update.html.twig', [
            'form' => $form->createView(),
            'post' => $post,
            'production' => $production,
        ]));
    }
public function updateAction ( string $ production_slug , int $ id , Request $ request , TokenStorageInterface $ token , AuthorizationCheckerInterface $ auth ) : Response { // Lookup the post and production. list ( $ post , $ production ) = $ this -> lookupEntity ( Post :: class , $ id , $ production_slug ) ; // Check permissions for this action. if ( ! $ auth -> isGranted ( 'edit' , $ post ) ) { throw new AccessDeniedException ( ) ; } // Get some basic information about the user. $ user = $ token -> getToken ( ) -> getUser ( ) ; // Create a new form for the post and handle. if ( null !== $ post -> getParent ( ) ) { $ form = $ this -> form -> create ( ReplyType :: class , $ post ) ; } else { $ form = $ this -> form -> create ( PostType :: class , $ post ) ; } // Handle the form submission. $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { // Flush entity manager, set success message and redirect. $ this -> em -> flush ( ) ; $ this -> session -> getFlashBag ( ) -> add ( 'success' , $ this -> translator -> trans ( 'post.updated' , [ ] , BkstgNoticeBoardBundle :: TRANSLATION_DOMAIN ) ) ; return new RedirectResponse ( $ this -> url_generator -> generate ( 'bkstg_board_show' , [ 'production_slug' => $ production -> getSlug ( ) ] ) ) ; } // Render the form. return new Response ( $ this -> templating -> render ( '@BkstgNoticeBoard/Post/update.html.twig' , [ 'form' => $ form -> createView ( ) , 'post' => $ post , 'production' => $ production , ] ) ) ; }
Update a post.

@param string                        $production_slug The production slug.
@param int                           $id              The id of the post.
@param Request                       $request         The incoming request.
@param TokenStorageInterface         $token           The token storage service.
@param AuthorizationCheckerInterface $auth            The authorization checker service.

@throws AccessDeniedException When the user is not a member of the production.

@return Response
Update a post .