denyAccessUnlessGranted('ROLE_GESTIONNAIRE'); $slot = $this->entityManager->find(ComposantSubcomponentSlot::class, $id); if (!$slot) { return $this->json(['success' => false, 'error' => 'Slot not found.'], 404); } $payload = json_decode($request->getContent(), true); if (!is_array($payload)) { return $this->json(['success' => false, 'error' => 'Invalid JSON payload.'], 400); } if (array_key_exists('selectedComposantId', $payload)) { if (null === $payload['selectedComposantId']) { $slot->setSelectedComposant(null); } else { $composant = $this->entityManager->find(Composant::class, $payload['selectedComposantId']); $slot->setSelectedComposant($composant); } } $this->entityManager->flush(); return $this->json([ 'success' => true, 'id' => $slot->getId(), 'selectedComposantId' => $slot->getSelectedComposant()?->getId(), ]); } }