Skip to content

Commit

Permalink
fix: Fixed missing entityManager flush to remove custom-form answer.
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Nov 20, 2023
1 parent 0ab294d commit e9aa0ba
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotNull;
use Themes\Rozier\RozierApp;
use Twig\Error\RuntimeError;

/**
* @package Themes\Rozier\Controllers
Expand All @@ -24,11 +25,12 @@ class CustomFormAnswersController extends RozierApp
* List every node-types.
*
* @param Request $request
* @param int $customFormId
* @param int $customFormId
*
* @return Response
* @throws RuntimeError
*/
public function listAction(Request $request, int $customFormId)
public function listAction(Request $request, int $customFormId): Response
{
$this->denyAccessUnlessGranted('ROLE_ACCESS_CUSTOMFORMS');
/*
Expand All @@ -55,58 +57,57 @@ public function listAction(Request $request, int $customFormId)
}

/**
* Return an deletion form for requested node-type.
* Return a deletion form for requested node-type.
*
* @param Request $request
* @param int $customFormAnswerId
*
* @return Response
* @throws RuntimeError
*/
public function deleteAction(Request $request, int $customFormAnswerId)
public function deleteAction(Request $request, int $customFormAnswerId): Response
{
$this->denyAccessUnlessGranted('ROLE_ACCESS_CUSTOMFORMS_DELETE');

$customFormAnswer = $this->em()->find(CustomFormAnswer::class, $customFormAnswerId);

if (null !== $customFormAnswer) {
$this->assignation['customFormAnswer'] = $customFormAnswer;

$form = $this->buildDeleteForm($customFormAnswer);

$form->handleRequest($request);

if (
$form->isSubmitted() &&
$form->isValid() &&
$form->getData()['customFormAnswerId'] == $customFormAnswer->getId()
) {
$this->em()->remove($customFormAnswer);

$msg = $this->getTranslator()->trans('customFormAnswer.%id%.deleted', ['%id%' => $customFormAnswer->getId()]);
$this->publishConfirmMessage($request, $msg);
/*
* Redirect to update schema page
*/
return $this->redirectToRoute(
'customFormAnswersHomePage',
["customFormId" => $customFormAnswer->getCustomForm()->getId()]
);
}

$this->assignation['form'] = $form->createView();
if (null === $customFormAnswer) {
throw new ResourceNotFoundException();
}

return $this->render('@RoadizRozier/custom-form-answers/delete.html.twig', $this->assignation);
$this->assignation['customFormAnswer'] = $customFormAnswer;
$form = $this->buildDeleteForm($customFormAnswer);
$form->handleRequest($request);

if (
$form->isSubmitted() &&
$form->isValid()
) {
$this->em()->remove($customFormAnswer);
$this->em()->flush();

$msg = $this->getTranslator()->trans('customFormAnswer.%id%.deleted', ['%id%' => $customFormAnswer->getId()]);
$this->publishConfirmMessage($request, $msg);
/*
* Redirect to update schema page
*/
return $this->redirectToRoute(
'customFormAnswersHomePage',
["customFormId" => $customFormAnswer->getCustomForm()->getId()]
);
}

throw new ResourceNotFoundException();
$this->assignation['form'] = $form->createView();

return $this->render('@RoadizRozier/custom-form-answers/delete.html.twig', $this->assignation);
}

/**
* @param CustomFormAnswer $customFormAnswer
*
* @return FormInterface
*/
private function buildDeleteForm(CustomFormAnswer $customFormAnswer)
private function buildDeleteForm(CustomFormAnswer $customFormAnswer): FormInterface
{
$builder = $this->createFormBuilder()
->add('customFormAnswerId', HiddenType::class, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

namespace Themes\Rozier\Controllers\CustomForms;

use Doctrine\Common\Collections\Collection;
use RZ\Roadiz\CoreBundle\Entity\CustomFormAnswer;
use RZ\Roadiz\CoreBundle\Entity\CustomFormFieldAttribute;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Themes\Rozier\RozierApp;
use Twig\Error\RuntimeError;

/**
* @package Themes\Rozier\Controllers
Expand All @@ -19,11 +20,12 @@ class CustomFormFieldAttributesController extends RozierApp
* List every node-types.
*
* @param Request $request
* @param int $customFormAnswerId
* @param int $customFormAnswerId
*
* @return \Symfony\Component\HttpFoundation\Response
* @return Response
* @throws RuntimeError
*/
public function listAction(Request $request, int $customFormAnswerId)
public function listAction(Request $request, int $customFormAnswerId): Response
{
$this->denyAccessUnlessGranted('ROLE_ACCESS_CUSTOMFORMS');
/*
Expand All @@ -42,10 +44,10 @@ public function listAction(Request $request, int $customFormAnswerId)
}

/**
* @param Collection|array $answers
* @param iterable $answers
* @return array
*/
protected function getAnswersByGroups($answers)
protected function getAnswersByGroups(iterable $answers): array
{
$fieldsArray = [];

Expand Down
Loading

0 comments on commit e9aa0ba

Please sign in to comment.