diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 37208c754..d036b6b1e 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -37,6 +37,7 @@ use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Form; +use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -122,22 +123,32 @@ class CalendarController extends AbstractController [$person, $accompanyingPeriod] = [$calendar->getPerson(), $calendar->getAccompanyingPeriod()]; + $form = $this->createForm(CancelType::class, $calendar); + if ($accompanyingPeriod instanceof AccompanyingPeriod) { $view = '@ChillCalendar/Calendar/cancelCalendarByAccompanyingCourse.html.twig'; -// $redirectRoute = $this->generateUrl('chill_calendar_calendar_list_by_period', ['id' => $accompanyingPeriod->getId()]); + $redirectRoute = $this->generateUrl('chill_calendar_calendar_list_by_period', ['id' => $accompanyingPeriod->getId()]); } elseif ($person instanceof Person) { $view = '@ChillCalendar/Calendar/cancelCalendarByPerson.html.twig'; -// $redirectRoute = $this->generateUrl('chill_calendar_calendar_list_by_person', ['id' => $person->getId()]); + $redirectRoute = $this->generateUrl('chill_calendar_calendar_list_by_person', ['id' => $person->getId()]); } else { throw new \RuntimeException('nor person or accompanying period'); } - // Cancellation form + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { + $this->em->persist($calendar); + $this->em->flush(); + + $this->addFlash('success', $this->translator->trans('calender.calendar item has been canceled!')); + + return new RedirectResponse($redirectRoute); + } return $this->render($view, [ 'calendar' => $calendar, -// 'delete_form' => $form->createView(), + 'form' => $form->createView(), 'accompanyingCourse' => $accompanyingPeriod, 'person' => $person, ]); diff --git a/src/Bundle/ChillCalendarBundle/Form/CancelType.php b/src/Bundle/ChillCalendarBundle/Form/CancelType.php index ad41a6105..f3a45968a 100644 --- a/src/Bundle/ChillCalendarBundle/Form/CancelType.php +++ b/src/Bundle/ChillCalendarBundle/Form/CancelType.php @@ -21,15 +21,19 @@ use Symfony\Component\OptionsResolver\OptionsResolver; class CancelType extends AbstractType { - public function __construct(private readonly TranslatableStringHelperInterface $translatableStringHelper) {} + public function __construct(private readonly TranslatableStringHelperInterface $translatableStringHelper) + { + } public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('cancelReason', EntityType::class, [ + $builder->add('cancelReason', EntityType::class, array( 'class' => CancelReason::class, - 'required' => true, - 'choice_label' => fn (CancelReason $cancelReason) => $this->translatableStringHelper->localize($cancelReason->getName()), - ]); + 'required' => false, + 'choice_label' => function (CancelReason $cancelReason) { + return $this->translatableStringHelper->localize($cancelReason->getName()); + }, + )); } public function configureOptions(OptionsResolver $resolver) diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByAccompanyingCourse.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByAccompanyingCourse.html.twig index 19659c627..10841bf9f 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByAccompanyingCourse.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByAccompanyingCourse.html.twig @@ -3,3 +3,20 @@ {% set activeRouteKey = 'chill_calendar_calendar_list' %} {% block title 'chill_calendar.cancel_calendar_item'|trans %} + +{% block content %} + + {{ form(form) }} + +
+ +{% endblock %} diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByPerson.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByPerson.html.twig index b3db97e0f..867a5b548 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByPerson.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/cancelCalendarByPerson.html.twig @@ -3,3 +3,20 @@ {% set activeRouteKey = 'chill_calendar_calendar_list' %} {% block title 'chill_calendar.cancel_calendar_item'|trans %} + +{% block content %} + + {{ form_row(form.cancelReason) }} + + + +{% endblock %}