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

        // Ensure the user is a member of the production.
        if (!$auth->isGranted('GROUP_ROLE_EDITOR', $production)) {
            throw new AccessDeniedException();
        }

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

        // Create a new active resource.
        $resource = new Resource();
        $resource->setAuthor($user->getUsername());
        $resource->setActive(true);
        $resource->setPinned(false);
        $resource->addGroup($production);

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

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

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

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

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

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

        // Ensure the user is a member of the production.
        if (!$auth->isGranted('GROUP_ROLE_EDITOR', $production)) {
            throw new AccessDeniedException();
        }

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

        // Create a new active resource.
        $resource = new Resource();
        $resource->setAuthor($user->getUsername());
        $resource->setActive(true);
        $resource->setPinned(false);
        $resource->addGroup($production);

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

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

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

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

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

        // Render the form.
        return new Response($this->templating->render(
            '@BkstgResource/Resource/create.html.twig',
            [
                'form' => $form->createView(),
                'production' => $production,
            ]
        ));
    }
public function createAction ( string $ production_slug , TokenStorageInterface $ token , AuthorizationCheckerInterface $ auth , Request $ request ) : Response { // Lookup the production. $ production_repo = $ this -> em -> getRepository ( Production :: class ) ; if ( null === $ production = $ production_repo -> findOneBy ( [ 'slug' => $ production_slug ] ) ) { throw new NotFoundHttpException ( ) ; } // Ensure the user is a member of the production. if ( ! $ auth -> isGranted ( 'GROUP_ROLE_EDITOR' , $ production ) ) { throw new AccessDeniedException ( ) ; } // Get some information about the user. $ user = $ token -> getToken ( ) -> getUser ( ) ; // Create a new active resource. $ resource = new Resource ( ) ; $ resource -> setAuthor ( $ user -> getUsername ( ) ) ; $ resource -> setActive ( true ) ; $ resource -> setPinned ( false ) ; $ resource -> addGroup ( $ production ) ; // Create and handle the form. $ form = $ this -> form -> create ( ResourceType :: class , $ resource ) ; $ form -> handleRequest ( $ request ) ; // Form is valid, persist and flush. if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { // Cascade active property to media. if ( null !== $ media = $ resource -> getMedia ( ) ) { $ media -> setActive ( $ resource -> isActive ( ) ) ; } $ this -> em -> persist ( $ resource ) ; $ this -> em -> flush ( ) ; // Set success message and redirect. $ this -> session -> getFlashBag ( ) -> add ( 'success' , $ this -> translator -> trans ( 'resource.created' , [ ] , 'BkstgResourceBundle' ) ) ; return new RedirectResponse ( $ this -> url_generator -> generate ( 'bkstg_resource_read' , [ 'id' => $ resource -> getId ( ) , 'production_slug' => $ production -> getSlug ( ) , ] ) ) ; } // Render the form. return new Response ( $ this -> templating -> render ( '@BkstgResource/Resource/create.html.twig' , [ 'form' => $ form -> createView ( ) , 'production' => $ production , ] ) ) ; }
Create a new resource in a production.

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

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

@return Response
Create a new resource in a production .