- toolbar and fixes
This commit is contained in:
Jérémy Guillot
2024-06-29 14:51:10 +02:00
parent b04055ec22
commit 858a5bed06
20 changed files with 404 additions and 68 deletions

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Twig\Components;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveProp;
use Symfony\UX\LiveComponent\DefaultActionTrait;
#[AsLiveComponent]
class DropdownMenu
{
use DefaultActionTrait;
#[LiveProp (writable: true)]
public ?array $items = null;
}

View File

@@ -8,6 +8,7 @@ use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveAction;
use Symfony\UX\LiveComponent\Attribute\LiveProp;
@@ -27,6 +28,11 @@ class NewMangaForm
#[LiveProp(writable: true)]
public ?int $index = 0;
public function __construct(private UrlGeneratorInterface $urlGenerator)
{
}
public function mount(Manga $manga): void
{
$this->manga = $manga;
@@ -84,6 +90,8 @@ class NewMangaForm
$manga->addChapter($chapter);
}
$mangaChapterUrl = $this->urlGenerator->generate('app_manga_show', ['mangaSlug' => $manga->getSlug()]);
try {
foreach ($manga->getChapters() as $chapter) {
$entityManager->persist($chapter);
@@ -93,11 +101,11 @@ class NewMangaForm
$entityManager->flush();
} catch (\Exception $e) {
if ($e instanceof UniqueConstraintViolationException) {
return new RedirectResponse('/manga/' . $manga->getSlug());
return new RedirectResponse($mangaChapterUrl);
}
throw $e;
}
return new RedirectResponse('/manga/' . $manga->getSlug());
return new RedirectResponse($mangaChapterUrl);
}
}