diff --git a/src/Twig/InlineEditBook.php b/src/Twig/InlineEditBook.php index 0ccc9b0c..d6f2f77f 100644 --- a/src/Twig/InlineEditBook.php +++ b/src/Twig/InlineEditBook.php @@ -5,6 +5,7 @@ use App\Entity\Book; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; use Symfony\UX\LiveComponent\Attribute\LiveAction; use Symfony\UX\LiveComponent\Attribute\LiveProp; @@ -39,9 +40,27 @@ public function activateEditing(): void $this->isEditing = true; } + /** + * @throws \JsonException + */ #[LiveAction] - public function save(EntityManagerInterface $entityManager): void + public function save(Request $request, EntityManagerInterface $entityManager): void { + $all = $request->request->all(); + if (!array_key_exists('data', $all)) { + return; + } + if (!is_string($all['data'])) { + return; + } + $data = json_decode($all['data'], true, 512, JSON_THROW_ON_ERROR); + if (!is_array($data)) { + return; + } + if (array_key_exists('updated', $data) && is_array($data['updated']) && array_key_exists('book.serieIndex', $data['updated']) && '' === $data['updated']['book.serieIndex']) { + $this->book->setSerieIndex(null); + } + $entityManager->flush(); $this->dispatchBrowserEvent('manager:flush'); $this->isEditing = false; diff --git a/templates/components/InlineEditBook.html.twig b/templates/components/InlineEditBook.html.twig index 351d63f6..2b809c92 100644 --- a/templates/components/InlineEditBook.html.twig +++ b/templates/components/InlineEditBook.html.twig @@ -13,6 +13,15 @@ autofocus id="book_{{ book.id }}_{{ field }}" /> + {% elseif field=='serieIndex' %} + {% else %}