diff --git a/src/Controller/SearchController.php b/src/Controller/SearchController.php index c7451b83e..6ea334cd6 100644 --- a/src/Controller/SearchController.php +++ b/src/Controller/SearchController.php @@ -14,6 +14,7 @@ use App\Service\SettingsManager; use App\Service\SubjectOverviewManager; use Psr\Log\LoggerInterface; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Messenger\MessageBusInterface; @@ -72,14 +73,27 @@ public function __invoke(Request $request): Response $user = $this->getUser(); $res = $this->manager->findPaginated($user, $query, $this->getPageNb($request)); + $params = [ + 'objects' => $objects, + 'results' => $this->overviewManager->buildList($res), + 'pagination' => $res, + 'q' => $request->query->get('q'), + ]; + + if ($request->isXmlHttpRequest()) { + return new JsonResponse( + [ + 'html' => $this->renderView( + 'search/_list.html.twig', + $params, + ), + ] + ); + } + return $this->render( 'search/front.html.twig', - [ - 'objects' => $objects, - 'results' => $this->overviewManager->buildList($res), - 'pagination' => $res, - 'q' => $request->query->get('q'), - ] + $params, ); } diff --git a/templates/search/_list.html.twig b/templates/search/_list.html.twig new file mode 100644 index 000000000..b864cbdf7 --- /dev/null +++ b/templates/search/_list.html.twig @@ -0,0 +1,7 @@ +