<?php
declare(strict_types=1);
namespace App\Component\ExternalIntegration\Integration\RecruitNowCockpit\EventSubscriber;
use App\Component\ExternalIntegration\Integration\RecruitNowCockpit\RecruitNowCockpit;
use App\Event\PreOpenApplicationEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;
final class RecruitNowCockpitApplicationSubscriber implements EventSubscriberInterface
{
public function __construct(private readonly Environment $twig)
{
}
public static function getSubscribedEvents(): array
{
return [PreOpenApplicationEvent::class => 'preOpenApplication'];
}
public function preOpenApplication(PreOpenApplicationEvent $preOpenApplicationEvent): void
{
$applicantForm = $preOpenApplicationEvent->getApplicantForm();
if (
RecruitNowCockpit::getReference() !== $applicantForm->getExternalReference()
|| null === $applicantForm->getExternalVacancyId()
|| '' === $applicantForm->getExternalVacancyId()
) {
return;
}
$body = $this->twig->render('@default/pages/form/recruit_now_open_apply.html.twig', [
'applicantForm' => $applicantForm,
]);
$preOpenApplicationEvent->setResponse(new Response($body));
}
}