src/Controller/Opinion/OpinionController.php
/**
     * Adding one Opinion on an existing Reduction and return a response (handled by AJAX).
     * If the form is valid, data are persisted and the page is reloaded (a simple POST action).
     * If not, form errors are sent in error Ajax function.
     *
     * @Route("/comment/{slug}", name="comment", methods={"GET", "POST"})
     */
Adding one Opinion on an existing Reduction and return a response (handled by AJAX).
If the form is valid, data are persisted and the page is reloaded (a simple POST action).
If not, form errors are sent in error Ajax function.


Adding one Opinion on an existing Reduction and return a response ( handled by AJAX ) . If the form is valid data are persisted and the page is reloaded ( a simple POST action ) . If not form errors are sent in error Ajax function .
public function comment(Request $request, Reduction $reduction): Response
    {
        $form = $this->createForm(OpinionType::class);
        $form->handleRequest($request);
        if ($reduction && $form->isSubmitted() && $form->isValid()) {
            $this->repositoryAdapter->save(
                $this->opinionManager->prepare(
                    $form->getData(),
                    $reduction,
                    $request->getClientIp(),
                    $this->getUser()
                ),
            );
            return new Response('Page is reloaded for flash messages and comments.');
        }
        return new Response(
            $this->renderView('opinion/_comment_form.html.twig', [
                'form' => $form->createView(),
            ]),
            Response::HTTP_UNPROCESSABLE_ENTITY
        );
    }
public function comment ( Request $ request , Reduction $ reduction ) : Response { $ form = $ this -> createForm ( OpinionType :: class ) ; $ form -> handleRequest ( $ request ) ; if ( $ reduction && $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { $ this -> repositoryAdapter -> save ( $ this -> opinionManager -> prepare ( $ form -> getData ( ) , $ reduction , $ request -> getClientIp ( ) , $ this -> getUser ( ) ) , ) ; return new Response ( 'Page is reloaded for flash messages and comments.' ) ; } return new Response ( $ this -> renderView ( 'opinion/_comment_form.html.twig' , [ 'form' => $ form -> createView ( ) , ] ) , Response :: HTTP_UNPROCESSABLE_ENTITY ) ; }
Adding one Opinion on an existing Reduction and return a response (handled by AJAX).
Adding one Opinion on an existing Reduction and return a response ( handled by AJAX ) .