mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fix edit request for event bundle
This commit is contained in:
parent
29f6a43288
commit
dd7d126bec
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace Chill\EventBundle\Form;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Form\StoredObjectType;
|
||||
use Chill\EventBundle\Entity\Event;
|
||||
use Chill\EventBundle\Form\Type\PickEventTypeType;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Form\Type\ChillCollectionType;
|
||||
@ -23,6 +24,7 @@ use Chill\MainBundle\Form\Type\PickUserLocationType;
|
||||
use Chill\MainBundle\Form\Type\ScopePickerType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@ -31,7 +33,9 @@ class EventType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('name')
|
||||
->add('name', TextType::class, [
|
||||
'required' => true
|
||||
])
|
||||
->add('date', ChillDateTimeType::class, [
|
||||
'required' => true,
|
||||
])
|
||||
@ -75,7 +79,7 @@ class EventType extends AbstractType
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => \Chill\EventBundle\Entity\Event::class,
|
||||
'data_class' => Event::class,
|
||||
]);
|
||||
$resolver
|
||||
->setRequired(['center', 'role'])
|
||||
|
Loading…
x
Reference in New Issue
Block a user