Fix delete request for all entities

This commit is contained in:
Julie Lenaerts 2024-07-17 13:05:14 +02:00
parent ead1abb825
commit 74be6460d4
11 changed files with 20 additions and 31 deletions

View File

@ -99,10 +99,10 @@ final class ActivityController extends AbstractController
$form = $this->createDeleteForm($activity->getId(), $person, $accompanyingPeriod); $form = $this->createDeleteForm($activity->getId(), $person, $accompanyingPeriod);
if (Request::METHOD_DELETE === $request->getMethod()) { if (Request::METHOD_POST === $request->getMethod()) {
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$this->logger->notice('An activity has been removed', [ $this->logger->notice('An activity has been removed', [
'by_user' => $this->getUser()->getUsername(), 'by_user' => $this->getUser()->getUsername(),
'activity_id' => $activity->getId(), 'activity_id' => $activity->getId(),
@ -640,7 +640,6 @@ final class ActivityController extends AbstractController
return $this->createFormBuilder() return $this->createFormBuilder()
->setAction($this->generateUrl('chill_activity_activity_delete', $params)) ->setAction($this->generateUrl('chill_activity_activity_delete', $params))
->setMethod('DELETE')
->add('submit', SubmitType::class, ['label' => 'Delete']) ->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm(); ->getForm();
} }

View File

@ -54,7 +54,7 @@ abstract class AbstractElementController extends AbstractController
$indexPage = 'chill_budget_elements_household_index'; $indexPage = 'chill_budget_elements_household_index';
} }
if (Request::METHOD_DELETE === $request->getMethod()) { if (Request::METHOD_POST === $request->getMethod()) {
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
@ -198,10 +198,9 @@ abstract class AbstractElementController extends AbstractController
/** /**
* Creates a form to delete a help request entity by id. * Creates a form to delete a help request entity by id.
*/ */
private function createDeleteForm(): Form private function createDeleteForm(): \Symfony\Component\Form\FormInterface
{ {
return $this->createFormBuilder() return $this->createFormBuilder()
->setMethod(Request::METHOD_DELETE)
->add('submit', SubmitType::class, ['label' => 'Delete']) ->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm(); ->getForm();
} }

View File

@ -84,7 +84,7 @@ class CalendarController extends AbstractController
$form = $this->createDeleteForm($entity); $form = $this->createDeleteForm($entity);
if (Request::METHOD_DELETE === $request->getMethod()) { if (Request::METHOD_POST === $request->getMethod()) {
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isValid()) { if ($form->isValid()) {
@ -512,7 +512,6 @@ class CalendarController extends AbstractController
{ {
return $this->createFormBuilder() return $this->createFormBuilder()
->setAction($this->generateUrl('chill_calendar_calendar_delete', ['id' => $calendar->getId()])) ->setAction($this->generateUrl('chill_calendar_calendar_delete', ['id' => $calendar->getId()]))
->setMethod('DELETE')
->add('submit', SubmitType::class, ['label' => 'Delete']) ->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm(); ->getForm();
} }

View File

@ -61,7 +61,7 @@ final class EventController extends AbstractController
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry
) {} ) {}
#[\Symfony\Component\Routing\Annotation\Route(path: '/{_locale}/event/event/{event_id}/delete', name: 'chill_event__event_delete', requirements: ['event_id' => '\d+'], methods: ['GET', 'DELETE'])] #[\Symfony\Component\Routing\Annotation\Route(path: '/{_locale}/event/event/{event_id}/delete', name: 'chill_event__event_delete', requirements: ['event_id' => '\d+'], methods: ['GET', 'POST', 'DELETE'])]
public function deleteAction($event_id, Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|Response public function deleteAction($event_id, Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|Response
{ {
$em = $this->managerRegistry->getManager(); $em = $this->managerRegistry->getManager();
@ -78,10 +78,10 @@ final class EventController extends AbstractController
$form = $this->createDeleteForm($event_id); $form = $this->createDeleteForm($event_id);
if (Request::METHOD_DELETE === $request->getMethod()) { if (Request::METHOD_POST === $request->getMethod()) {
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
foreach ($participations as $participation) { foreach ($participations as $participation) {
$em->remove($participation); $em->remove($participation);
} }
@ -599,7 +599,6 @@ final class EventController extends AbstractController
->setAction($this->generateUrl('chill_event__event_delete', [ ->setAction($this->generateUrl('chill_event__event_delete', [
'event_id' => $event_id, 'event_id' => $event_id,
])) ]))
->setMethod('DELETE')
->add('submit', SubmitType::class, ['label' => 'Delete']) ->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm(); ->getForm();
} }

View File

@ -201,7 +201,7 @@ class EventTypeController extends AbstractController
/** /**
* Creates a form to delete a EventType entity by id. * Creates a form to delete a EventType entity by id.
* *
* @return \Symfony\Component\Form\Form The form * @return \Symfony\Component\Form\FormInterface The form
*/ */
private function createDeleteForm(mixed $id) private function createDeleteForm(mixed $id)
{ {
@ -210,7 +210,6 @@ class EventTypeController extends AbstractController
'chill_eventtype_admin_delete', 'chill_eventtype_admin_delete',
['id' => $id] ['id' => $id]
)) ))
->setMethod('DELETE')
->add('submit', SubmitType::class, ['label' => 'Delete']) ->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm(); ->getForm();
} }

View File

@ -259,10 +259,10 @@ final class ParticipationController extends AbstractController
$form = $this->createDeleteForm($participation_id); $form = $this->createDeleteForm($participation_id);
if (Request::METHOD_DELETE === $request->getMethod()) { if (Request::METHOD_POST === $request->getMethod()) {
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$em->remove($participation); $em->remove($participation);
$em->flush(); $em->flush();
@ -753,7 +753,6 @@ final class ParticipationController extends AbstractController
->setAction($this->generateUrl('chill_event_participation_delete', [ ->setAction($this->generateUrl('chill_event_participation_delete', [
'participation_id' => $participation_id, 'participation_id' => $participation_id,
])) ]))
->setMethod('DELETE')
->add('submit', SubmitType::class, ['label' => 'Delete']) ->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm(); ->getForm();
} }

View File

@ -201,7 +201,7 @@ class RoleController extends AbstractController
/** /**
* Creates a form to delete a Role entity by id. * Creates a form to delete a Role entity by id.
* *
* @return \Symfony\Component\Form\Form The form * @return \Symfony\Component\Form\FormInterface The form
*/ */
private function createDeleteForm(mixed $id) private function createDeleteForm(mixed $id)
{ {

View File

@ -80,10 +80,10 @@ final class AccompanyingCourseWorkController extends AbstractController
$form = $this->createDeleteForm($work->getId()); $form = $this->createDeleteForm($work->getId());
if (Request::METHOD_DELETE === $request->getMethod()) { if (Request::METHOD_POST === $request->getMethod()) {
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$this->chillLogger->notice('An accompanying period work has been removed', [ $this->chillLogger->notice('An accompanying period work has been removed', [
'by_user' => $this->getUser()->getUsername(), 'by_user' => $this->getUser()->getUsername(),
'work_id' => $work->getId(), 'work_id' => $work->getId(),
@ -179,7 +179,6 @@ final class AccompanyingCourseWorkController extends AbstractController
return $this->createFormBuilder() return $this->createFormBuilder()
->setAction($this->generateUrl('chill_person_accompanying_period_work_delete', $params)) ->setAction($this->generateUrl('chill_person_accompanying_period_work_delete', $params))
->setMethod('DELETE')
->add('submit', SubmitType::class, ['label' => 'Delete']) ->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm(); ->getForm();
} }

View File

@ -63,11 +63,10 @@ class HouseholdCompositionController extends AbstractController
'composition_id' => $composition_id, 'composition_id' => $composition_id,
'household_id' => $household_id, 'household_id' => $household_id,
])) ]))
->setMethod('DELETE')
->add('submit', SubmitType::class, ['label' => 'Delete']) ->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm(); ->getForm();
if (Request::METHOD_DELETE === $request->getMethod()) { if (Request::METHOD_POST === $request->getMethod()) {
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isValid()) { if ($form->isValid()) {

View File

@ -44,14 +44,13 @@ final class PersonResourceController extends AbstractController
'resource_id' => $resource_id, 'resource_id' => $resource_id,
'person_id' => $person_id, 'person_id' => $person_id,
])) ]))
->setMethod('DELETE')
->add('submit', SubmitType::class, ['label' => 'Delete']) ->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm(); ->getForm();
if (Request::METHOD_DELETE === $request->getMethod()) { if (Request::METHOD_POST === $request->getMethod()) {
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$this->em->remove($resource); $this->em->remove($resource);
$this->em->flush(); $this->em->flush();

View File

@ -62,7 +62,7 @@ final class SingleTaskController extends AbstractController
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry,
) {} ) {}
#[Route(path: '/{_locale}/task/single-task/{id}/delete', name: 'chill_task_single_task_delete')] #[Route(path: '/{_locale}/task/single-task/{id}/delete', name: 'chill_task_single_task_delete', methods: ['GET', 'POST', 'DELETE'])]
public function deleteAction(Request $request, mixed $id) public function deleteAction(Request $request, mixed $id)
{ {
$course = null; $course = null;
@ -110,10 +110,9 @@ final class SingleTaskController extends AbstractController
$form = $this->createDeleteForm($id); $form = $this->createDeleteForm($id);
if (Request::METHOD_DELETE === $request->getMethod()) { if (Request::METHOD_POST === $request->getMethod()) {
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if ($form->isValid()) {
$this->logger->notice('A task has been removed', [ $this->logger->notice('A task has been removed', [
'by_user' => $this->getUser()->getUsername(), 'by_user' => $this->getUser()->getUsername(),
'task_id' => $task->getId(), 'task_id' => $task->getId(),
@ -660,7 +659,6 @@ final class SingleTaskController extends AbstractController
'chill_task_single_task_delete', 'chill_task_single_task_delete',
['id' => $id] ['id' => $id]
)) ))
->setMethod('DELETE')
->add('submit', SubmitType::class, ['label' => 'Delete']) ->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm(); ->getForm();
} }