mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 10:33:49 +00:00
Fix edit request for event bundle
This commit is contained in:
@@ -313,7 +313,7 @@ final class EventController extends AbstractController
|
||||
/**
|
||||
* Edits an existing Event entity.
|
||||
*/
|
||||
#[\Symfony\Component\Routing\Annotation\Route(path: '/{_locale}/event/event/{event_id}/update', name: 'chill_event__event_update', methods: ['POST', 'PUT'])]
|
||||
#[\Symfony\Component\Routing\Annotation\Route(path: '/{_locale}/event/event/{event_id}/update', name: 'chill_event__event_update', methods: ['GET', 'POST', 'PUT'])]
|
||||
public function updateAction(Request $request, $event_id): \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
{
|
||||
$em = $this->managerRegistry->getManager();
|
||||
@@ -324,14 +324,20 @@ final class EventController extends AbstractController
|
||||
throw $this->createNotFoundException('Unable to find Event entity.');
|
||||
}
|
||||
|
||||
$editForm = $this->createEditForm($entity);
|
||||
$editForm = $this->createForm(EventType::class, $entity, [
|
||||
'center' => $entity->getCenter(),
|
||||
'role' => EventVoter::UPDATE,
|
||||
]);
|
||||
|
||||
$editForm->add('submit', SubmitType::class, ['label' => 'Update']);
|
||||
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isValid()) {
|
||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||
$em->persist($entity);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator
|
||||
->trans('The event was updated'));
|
||||
$this->addFlash('success', $this->translator->trans('The event was updated'));
|
||||
|
||||
return $this->redirectToRoute('chill_event__event_show', ['event_id' => $event_id]);
|
||||
}
|
||||
@@ -602,25 +608,4 @@ final class EventController extends AbstractController
|
||||
->add('submit', SubmitType::class, ['label' => 'Delete'])
|
||||
->getForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to edit a Event entity.
|
||||
*
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
private function createEditForm(Event $entity)
|
||||
{
|
||||
$form = $this->createForm(EventType::class, $entity, [
|
||||
'action' => $this->generateUrl('chill_event__event_update', ['event_id' => $entity->getId()]),
|
||||
'method' => 'PUT',
|
||||
'center' => $entity->getCenter(),
|
||||
'role' => 'CHILL_EVENT_CREATE',
|
||||
]);
|
||||
|
||||
$form->remove('center');
|
||||
|
||||
$form->add('submit', SubmitType::class, ['label' => 'Update']);
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user