feat: integrate with htmx

This commit is contained in:
Björn Fromme
2024-02-07 10:15:59 +01:00
parent 4d1799ca49
commit 1e572606f8
154 changed files with 1447 additions and 1461 deletions
@@ -6,13 +6,13 @@ use App\Entity\Contact;
use App\Entity\Upload;
use App\Entity\User;
use App\Form\ContactType;
use App\Model\AjaxModalResponseDto;
use App\Htmx\HxRedirectResponse;
use App\Service\Upload\UploadHandler;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
@@ -27,10 +27,8 @@ class EditController extends AbstractController
#[Route('/admin/system/contact/edit/{id}', name: 'app_admin_system_contact_edit')]
#[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(Contact $contact, Request $request): JsonResponse
public function index(Contact $contact, Request $request): Response
{
$response = new AjaxModalResponseDto();
$formAction = $this->generateUrl('app_admin_system_contact_edit', ['id' => $contact->getId()]);
// Handle upload independently from form submission to avoid issues with failing validation
$uploadSession = $this->uploadHandler->getUploadSession();
if (true === $request->isMethod('POST') && 0 < $uploadSession->getCount()) {
@@ -46,15 +44,7 @@ class EditController extends AbstractController
$this->uploadHandler->destroyUploadSession();
}
$form = $this->createForm(
ContactType::class,
$contact,
[
'action' => $formAction,
'ajax_submit' => true,
'upload_session' => $uploadSession,
]
);
$form = $this->createForm(ContactType::class, $contact, ['upload_session' => $uploadSession]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
@@ -65,13 +55,11 @@ class EditController extends AbstractController
'contact_name' => $contact->getName(),
]);
$response->setCloseAndRedirect($this->generateUrl('app_admin_system_contact_index'));
} else {
$response->setContent($this->renderView('admin/system/contact/edit.html.twig', [
'form' => $form,
]));
return new HxRedirectResponse($this->generateUrl('app_admin_system_contact_index'));
}
return $this->json($response);
return $this->render('admin/system/contact/modal_edit.html.twig', [
'form' => $form->createView(),
]);
}
}