Add category edit page, edit button, and drag & drop sortable with native HTML5
- Add /mon-compte/evenement/{id}/categorie/{categoryId}/modifier route (GET/POST)
- Create edit_category.html.twig with name and date fields
- Add edit button (pencil icon) on category list items
- Add sortable.js module: native HTML5 drag & drop with fetch reorder API
- Auto-correct endAt < startAt on category edit
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -429,6 +429,58 @@ class AccountController extends AbstractController
|
||||
return $this->redirectToRoute('app_account_edit_event', ['id' => $event->getId(), 'tab' => 'categories']);
|
||||
}
|
||||
|
||||
#[Route('/mon-compte/evenement/{id}/categorie/{categoryId}/modifier', name: 'app_account_event_edit_category', methods: ['GET', 'POST'])]
|
||||
public function editCategory(Event $event, int $categoryId, Request $request, EntityManagerInterface $em): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ROLE_ORGANIZER');
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
if ($event->getAccount()->getId() !== $user->getId()) {
|
||||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
$category = $em->getRepository(Category::class)->find($categoryId);
|
||||
if (!$category || $category->getEvent()->getId() !== $event->getId()) {
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
if ($request->isMethod('POST')) {
|
||||
$category->setName(trim($request->request->getString('name')));
|
||||
|
||||
$startAt = $request->request->getString('start_at');
|
||||
if ('' !== $startAt) {
|
||||
$category->setStartAt(new \DateTimeImmutable($startAt));
|
||||
}
|
||||
|
||||
$endAt = $request->request->getString('end_at');
|
||||
if ('' !== $endAt) {
|
||||
$category->setEndAt(new \DateTimeImmutable($endAt));
|
||||
}
|
||||
|
||||
if ($category->getEndAt() < $category->getStartAt()) {
|
||||
$category->setEndAt($category->getStartAt()->modify('+30 days'));
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', 'Categorie modifiee.');
|
||||
|
||||
return $this->redirectToRoute('app_account_edit_event', ['id' => $event->getId(), 'tab' => 'categories']);
|
||||
}
|
||||
|
||||
return $this->render('account/edit_category.html.twig', [
|
||||
'event' => $event,
|
||||
'category' => $category,
|
||||
'breadcrumbs' => [
|
||||
self::BREADCRUMB_HOME,
|
||||
self::BREADCRUMB_ACCOUNT,
|
||||
['name' => $event->getTitle(), 'url' => '/mon-compte/evenement/'.$event->getId().'/modifier?tab=categories'],
|
||||
['name' => $category->getName(), 'url' => ''],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/mon-compte/evenement/{id}/categorie/{categoryId}/supprimer', name: 'app_account_event_delete_category', methods: ['POST'])]
|
||||
public function deleteCategory(Event $event, int $categoryId, EntityManagerInterface $em): Response
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user