Skip to content

Commit

Permalink
Merge tag 'v2.1.51' into develop
Browse files Browse the repository at this point in the history
v2.1.51
  • Loading branch information
ambroisemaupate committed Nov 20, 2023
2 parents 3d123ff + 0fca740 commit a62c34f
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 102 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [v2.1.51](https://github.com/roadiz/core-bundle-dev-app/compare/v2.1.50...v2.1.51) (2023-11-20)


### Bug Fixes

* Fixed missing entityManager flush to remove custom-form answer. ([e9aa0ba](https://github.com/roadiz/core-bundle-dev-app/commit/e9aa0ba826244024426a0484a4e19a51008cbda2))

## [v2.1.50](https://github.com/roadiz/core-bundle-dev-app/compare/v2.1.49...v2.1.50) (2023-11-16)


Expand Down
2 changes: 1 addition & 1 deletion lib/RoadizTwoFactorBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"prefer-stable": true,
"require": {
"php": ">=8.0",
"doctrine/orm": "^2.14.1",
"doctrine/orm": "^2.14.1 < 2.17",
"endroid/qr-code": "^4.0",
"roadiz/core-bundle": "2.2.x-dev",
"roadiz/rozier-bundle": "2.2.x-dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotNull;
use Themes\Rozier\RozierApp;
use Twig\Error\RuntimeError;

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): Response
{
Expand Down Expand Up @@ -58,44 +60,43 @@ public function listAction(Request $request, int $customFormId): Response
* @param int $customFormAnswerId
*
* @return Response
* @throws RuntimeError
*/
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, $customFormAnswer);
/*
* 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, $customFormAnswer);
/*
* 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);
}

/**
Expand Down
141 changes: 72 additions & 69 deletions lib/Rozier/src/Controllers/CustomForms/CustomFormFieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class CustomFormFieldsController extends RozierApp
/**
* List every node-type-fields.
*
* @param Request $request
* @param int $customFormId
* @param int $customFormId
*
* @return Response
* @throws RuntimeError
*/
public function listAction(Request $request, int $customFormId): Response
public function listAction(int $customFormId): Response
{
$this->denyAccessUnlessGranted('ROLE_ACCESS_CUSTOMFORMS');

Expand All @@ -50,9 +50,10 @@ public function listAction(Request $request, int $customFormId): Response
* Return an edition form for requested node-type.
*
* @param Request $request
* @param int $customFormFieldId
* @param int $customFormFieldId
*
* @return Response
* @throws RuntimeError
*/
public function editAction(Request $request, int $customFormFieldId): Response
{
Expand All @@ -61,35 +62,35 @@ public function editAction(Request $request, int $customFormFieldId): Response
/** @var CustomFormField|null $field */
$field = $this->em()->find(CustomFormField::class, $customFormFieldId);

if ($field !== null) {
$this->assignation['customForm'] = $field->getCustomForm();
$this->assignation['field'] = $field;
$form = $this->createForm(CustomFormFieldType::class, $field);
$form->handleRequest($request);

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

$msg = $this->getTranslator()->trans('customFormField.%name%.updated', ['%name%' => $field->getName()]);
$this->publishConfirmMessage($request, $msg, $field);

/*
* Redirect to update schema page
*/
return $this->redirectToRoute(
'customFormFieldsListPage',
[
'customFormId' => $field->getCustomForm()->getId(),
]
);
}
if ($field === null) {
throw new ResourceNotFoundException();
}

$this->assignation['form'] = $form->createView();
$this->assignation['customForm'] = $field->getCustomForm();
$this->assignation['field'] = $field;
$form = $this->createForm(CustomFormFieldType::class, $field);
$form->handleRequest($request);

return $this->render('@RoadizRozier/custom-form-fields/edit.html.twig', $this->assignation);
if ($form->isSubmitted() && $form->isValid()) {
$this->em()->flush();

$msg = $this->getTranslator()->trans('customFormField.%name%.updated', ['%name%' => $field->getName()]);
$this->publishConfirmMessage($request, $msg, $field);

/*
* Redirect to update schema page
*/
return $this->redirectToRoute(
'customFormFieldsListPage',
[
'customFormId' => $field->getCustomForm()->getId(),
]
);
}

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

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

/**
Expand All @@ -112,6 +113,7 @@ public function addAction(Request $request, int $customFormId): Response

$field = new CustomFormField();
$field->setCustomForm($customForm);

$this->assignation['customForm'] = $customForm;
$this->assignation['field'] = $field;
$form = $this->createForm(CustomFormFieldType::class, $field);
Expand Down Expand Up @@ -159,65 +161,66 @@ public function addAction(Request $request, int $customFormId): Response
* Return a deletion form for requested node.
*
* @param Request $request
* @param int $customFormFieldId
* @param int $customFormFieldId
*
* @return Response
* @throws RuntimeError
*/
public function deleteAction(Request $request, int $customFormFieldId)
public function deleteAction(Request $request, int $customFormFieldId): Response
{
$this->denyAccessUnlessGranted('ROLE_ACCESS_CUSTOMFORMS_DELETE');

$field = $this->em()->find(CustomFormField::class, $customFormFieldId);

if ($field !== null) {
$this->assignation['field'] = $field;
$form = $this->buildDeleteForm($field);
$form->handleRequest($request);

if (
$form->isSubmitted() &&
$form->isValid() &&
$form->getData()['customFormFieldId'] == $field->getId()
) {
$customFormId = $field->getCustomForm()->getId();

$this->em()->remove($field);
$this->em()->flush();

/*
* Update Database
*/
$msg = $this->getTranslator()->trans(
'customFormField.%name%.deleted',
['%name%' => $field->getName()]
);
$this->publishConfirmMessage($request, $msg, $field);

/*
* Redirect to update schema page
*/
return $this->redirectToRoute(
'customFormFieldsListPage',
[
'customFormId' => $customFormId,
]
);
}
if ($field === null) {
throw new ResourceNotFoundException();
}

$this->assignation['form'] = $form->createView();
$this->assignation['field'] = $field;
$form = $this->buildDeleteForm($field);
$form->handleRequest($request);

return $this->render('@RoadizRozier/custom-form-fields/delete.html.twig', $this->assignation);
if (
$form->isSubmitted() &&
$form->isValid() &&
$form->getData()['customFormFieldId'] == $field->getId()
) {
$customFormId = $field->getCustomForm()->getId();

$this->em()->remove($field);
$this->em()->flush();

/*
* Update Database
*/
$msg = $this->getTranslator()->trans(
'customFormField.%name%.deleted',
['%name%' => $field->getName()]
);
$this->publishConfirmMessage($request, $msg);

/*
* Redirect to update schema page
*/
return $this->redirectToRoute(
'customFormFieldsListPage',
[
'customFormId' => $customFormId,
]
);
}

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

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

/**
* @param CustomFormField $field
*
* @return FormInterface
*/
private function buildDeleteForm(CustomFormField $field)
private function buildDeleteForm(CustomFormField $field): FormInterface
{
$builder = $this->createFormBuilder()
->add('customFormFieldId', HiddenType::class, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Themes\Rozier\Controllers\CustomForms;

use PhpOffice\PhpSpreadsheet\Exception;
use RZ\Roadiz\CoreBundle\Entity\CustomForm;
use RZ\Roadiz\CoreBundle\Entity\CustomFormAnswer;
use RZ\Roadiz\CoreBundle\CustomForm\CustomFormAnswerSerializer;
Expand All @@ -29,11 +30,13 @@ public function __construct(CustomFormAnswerSerializer $customFormAnswerSerializ
* Export all custom form's answer in a Xlsx file (.rzt).
*
* @param Request $request
* @param int $id
* @param int $id
*
* @return Response
* @throws Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
public function exportAction(Request $request, int $id)
public function exportAction(Request $request, int $id): Response
{
/** @var CustomForm|null $customForm */
$customForm = $this->em()->find(CustomForm::class, $id);
Expand Down Expand Up @@ -90,7 +93,7 @@ public function exportAction(Request $request, int $id)
*
* @return Response
*/
public function duplicateAction(Request $request, int $id)
public function duplicateAction(Request $request, int $id): Response
{
$this->denyAccessUnlessGranted('ROLE_ACCESS_CUSTOMFORMS');
/** @var CustomForm|null $existingCustomForm */
Expand Down

0 comments on commit a62c34f

Please sign in to comment.