src/Component/ExternalIntegration/Integration/RecruitNowCockpit/EventSubscriber/RecruitNowCockpitApplicationSubscriber.php line 24

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Component\ExternalIntegration\Integration\RecruitNowCockpit\EventSubscriber;
  4. use App\Component\ExternalIntegration\Integration\RecruitNowCockpit\RecruitNowCockpit;
  5. use App\Event\PreOpenApplicationEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Twig\Environment;
  9. final class RecruitNowCockpitApplicationSubscriber implements EventSubscriberInterface
  10. {
  11.     public function __construct(private readonly Environment $twig)
  12.     {
  13.     }
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [PreOpenApplicationEvent::class => 'preOpenApplication'];
  17.     }
  18.     public function preOpenApplication(PreOpenApplicationEvent $preOpenApplicationEvent): void
  19.     {
  20.         $applicantForm $preOpenApplicationEvent->getApplicantForm();
  21.         if (
  22.             RecruitNowCockpit::getReference() !== $applicantForm->getExternalReference()
  23.             || null === $applicantForm->getExternalVacancyId()
  24.             || '' === $applicantForm->getExternalVacancyId()
  25.         ) {
  26.             return;
  27.         }
  28.         $body $this->twig->render('@default/pages/form/recruit_now_open_apply.html.twig', [
  29.             'applicantForm' => $applicantForm,
  30.         ]);
  31.         $preOpenApplicationEvent->setResponse(new Response($body));
  32.     }
  33. }