public function settingsAction(
        string $production_slug,
        Request $request,
        AuthorizationCheckerInterface $auth
    ): Response {
        // Lookup the production by slug.
        if (null === $production = $this->em->getRepository(Production::class)->findOneBy(
            ['slug' => $production_slug]
        )) {
            throw new NotFoundHttpException();
        }

        // Must be an admin to edit settings.
        if (!$auth->isGranted('GROUP_ROLE_ADMIN', $production)) {
            throw new AccessDeniedException();
        }

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

        // If form is submitted and valid.
        if ($form->isSubmitted() && $form->isValid()) {
            // Cascade active property to image.
            if (null !== $image = $production->getImage()) {
                $image->setActive($production->isActive());
            }

            // Cascade active property to banner.
            if (null !== $banner = $production->getBanner()) {
                $banner->setActive($production->isActive());
            }

            $this->em->persist($production);
            $this->em->flush();

            // Set success message and redirect.
            $this->session->getFlashBag()->add(
                'success',
                $this->translator->trans('production.edited', [
                    '%production%' => $production->getName(),
                ], BkstgCoreBundle::TRANSLATION_DOMAIN)
            );

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

        // Render the form.
        return new Response($this->templating->render('@BkstgCore/Production/settings.html.twig', [
            'form' => $form->createView(),
            'production' => $production,
        ]));
    }
public function settingsAction(
        string $production_slug,
        Request $request,
        AuthorizationCheckerInterface $auth
    ): Response {
        // Lookup the production by slug.
        if (null === $production = $this->em->getRepository(Production::class)->findOneBy(
            ['slug' => $production_slug]
        )) {
            throw new NotFoundHttpException();
        }

        // Must be an admin to edit settings.
        if (!$auth->isGranted('GROUP_ROLE_ADMIN', $production)) {
            throw new AccessDeniedException();
        }

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

        // If form is submitted and valid.
        if ($form->isSubmitted() && $form->isValid()) {
            // Cascade active property to image.
            if (null !== $image = $production->getImage()) {
                $image->setActive($production->isActive());
            }

            // Cascade active property to banner.
            if (null !== $banner = $production->getBanner()) {
                $banner->setActive($production->isActive());
            }

            $this->em->persist($production);
            $this->em->flush();

            // Set success message and redirect.
            $this->session->getFlashBag()->add(
                'success',
                $this->translator->trans('production.edited', [
                    '%production%' => $production->getName(),
                ], BkstgCoreBundle::TRANSLATION_DOMAIN)
            );

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

        // Render the form.
        return new Response($this->templating->render('@BkstgCore/Production/settings.html.twig', [
            'form' => $form->createView(),
            'production' => $production,
        ]));
    }
public function settingsAction ( string $ production_slug , Request $ request , AuthorizationCheckerInterface $ auth ) : Response { // Lookup the production by slug. if ( null === $ production = $ this -> em -> getRepository ( Production :: class ) -> findOneBy ( [ 'slug' => $ production_slug ] ) ) { throw new NotFoundHttpException ( ) ; } // Must be an admin to edit settings. if ( ! $ auth -> isGranted ( 'GROUP_ROLE_ADMIN' , $ production ) ) { throw new AccessDeniedException ( ) ; } // Create and handle the form. $ form = $ this -> form -> create ( ProductionSettingsType :: class , $ production ) ; $ form -> handleRequest ( $ request ) ; // If form is submitted and valid. if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { // Cascade active property to image. if ( null !== $ image = $ production -> getImage ( ) ) { $ image -> setActive ( $ production -> isActive ( ) ) ; } // Cascade active property to banner. if ( null !== $ banner = $ production -> getBanner ( ) ) { $ banner -> setActive ( $ production -> isActive ( ) ) ; } $ this -> em -> persist ( $ production ) ; $ this -> em -> flush ( ) ; // Set success message and redirect. $ this -> session -> getFlashBag ( ) -> add ( 'success' , $ this -> translator -> trans ( 'production.edited' , [ '%production%' => $ production -> getName ( ) , ] , BkstgCoreBundle :: TRANSLATION_DOMAIN ) ) ; return new RedirectResponse ( $ this -> url_generator -> generate ( 'bkstg_production_settings' , [ 'production_slug' => $ production -> getSlug ( ) , ] ) ) ; } // Render the form. return new Response ( $ this -> templating -> render ( '@BkstgCore/Production/settings.html.twig' , [ 'form' => $ form -> createView ( ) , 'production' => $ production , ] ) ) ; }
Provide a generic settings form for admins.

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

@throws NotFoundHttpException When the production is not found.
@throws AccessDeniedException When the user doesn't have access to the production.

@return Response The rendered response.
Provide a generic settings form for admins .