source/View/Controller/NavigationController.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\View\Controller;
  3. use App\Domain\Model\Study\Experiment;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\Form\FormView;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. class NavigationController extends AbstractController
  10. {
  11.     private EntityManagerInterface $em;
  12.     /**
  13.      * @param EntityManagerInterface $em
  14.      */
  15.     public function __construct(EntityManagerInterface $em)
  16.     {
  17.         $this->em $em;
  18.     }
  19.     public function sidebarNavigationAction(Request $request): Response
  20.     {
  21.         $uuid $request->get('uuid'); // magic string refer to the name of your slug :)
  22.         return $this->render('Components/_navigationSidebar.html.twig', [
  23.             'experiment' => $this->getEntityAtChange($uuid),
  24.         ]);
  25.     }
  26.     public function savebarNavigationAction(
  27.         Request $request,
  28.         ?string $prevUrl,
  29.         ?string $prevTitle,
  30.         ?string $nextUrl,
  31.         ?string $nextTitle,
  32.         ?FormView $form
  33.     ): Response {
  34.         $uuid $request->get('uuid'); // still a magic strings
  35.         return $this->render('Components/_navigationSavebar.html.twig', [
  36.             'experiment' => $this->getEntityAtChange($uuid),
  37.             'prevUrl' => $prevUrl $this->generateUrl($prevUrl, ['uuid' => $uuid]) : null,
  38.             'prevTitle' => $prevTitle,
  39.             'nextUrl' => $nextUrl $this->generateUrl($nextUrl, ['uuid' => $uuid]) : null,
  40.             'nextTitle' => $nextTitle,
  41.             'form' => $form,
  42.         ]);
  43.     }
  44.     protected function getEntityAtChange(string $uuidstring $className Experiment::class)
  45.     {
  46.         return $this->em->getRepository($className)->find($uuid);
  47.     }
  48. }