public function updateAction(
        int $id,
        string $production_slug,
        Request $request,
        AuthorizationCheckerInterface $auth
    ): Response {
        // Lookup the resource and production.
        list($resource, $production) = $this->lookupEntity(Resource::class, $id, $production_slug);

        // Check access to the resource.
        if (!$auth->isGranted('edit', $resource)) {
            throw new AccessDeniedException();
        }

        // Create and handle the form.
        $form = $this->form->create(ResourceType::class, $resource);
        $form->handleRequest($request);

        // Form is submitted, flush changes.
        if ($form->isSubmitted() && $form->isValid()) {
            // Cascade active property to media.
            if (null !== $media = $resource->getMedia()) {
                $media->setActive($resource->isActive());
            }

            $this->em->flush();

            // Set success message and redirect.
            $this->session->getFlashBag()->add(
                'success',
                $this->translator->trans('resource.updated', ['%name%' => $resource->getName()], 'BkstgResourceBundle')
            );

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

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

        // Check access to the resource.
        if (!$auth->isGranted('edit', $resource)) {
            throw new AccessDeniedException();
        }

        // Create and handle the form.
        $form = $this->form->create(ResourceType::class, $resource);
        $form->handleRequest($request);

        // Form is submitted, flush changes.
        if ($form->isSubmitted() && $form->isValid()) {
            // Cascade active property to media.
            if (null !== $media = $resource->getMedia()) {
                $media->setActive($resource->isActive());
            }

            $this->em->flush();

            // Set success message and redirect.
            $this->session->getFlashBag()->add(
                'success',
                $this->translator->trans('resource.updated', ['%name%' => $resource->getName()], 'BkstgResourceBundle')
            );

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

        // Render the response.
        return new Response($this->templating->render(
            '@BkstgResource/Resource/update.html.twig',
            [
                'resource' => $resource,
                'form' => $form->createView(),
                'production' => $production,
            ]
        ));
    }
public function updateAction ( int $ id , string $ production_slug , Request $ request , AuthorizationCheckerInterface $ auth ) : Response { // Lookup the resource and production. list ( $ resource , $ production ) = $ this -> lookupEntity ( Resource :: class , $ id , $ production_slug ) ; // Check access to the resource. if ( ! $ auth -> isGranted ( 'edit' , $ resource ) ) { throw new AccessDeniedException ( ) ; } // Create and handle the form. $ form = $ this -> form -> create ( ResourceType :: class , $ resource ) ; $ form -> handleRequest ( $ request ) ; // Form is submitted, flush changes. if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { // Cascade active property to media. if ( null !== $ media = $ resource -> getMedia ( ) ) { $ media -> setActive ( $ resource -> isActive ( ) ) ; } $ this -> em -> flush ( ) ; // Set success message and redirect. $ this -> session -> getFlashBag ( ) -> add ( 'success' , $ this -> translator -> trans ( 'resource.updated' , [ '%name%' => $ resource -> getName ( ) ] , 'BkstgResourceBundle' ) ) ; return new RedirectResponse ( $ this -> url_generator -> generate ( 'bkstg_resource_read' , [ 'id' => $ resource -> getId ( ) , 'production_slug' => $ production -> getSlug ( ) , ] ) ) ; } // Render the response. return new Response ( $ this -> templating -> render ( '@BkstgResource/Resource/update.html.twig' , [ 'resource' => $ resource , 'form' => $ form -> createView ( ) , 'production' => $ production , ] ) ) ; }
Update a resource for this production.

@param int                           $id              The resource id.
@param string                        $production_slug The production slug.
@param Request                       $request         The incoming request.
@param AuthorizationCheckerInterface $auth            The authorization checker service.

@throws AccessDeniedException When the user does not have access to edit the resource.

@return Response
Update a resource for this production .