src/EventListener/RegionContactListener.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Component\Configuration\Util\Config;
  4. use App\Event\RegionContactSubmitEvent;
  5. use App\Sendgrid\MailerInterface;
  6. use App\Service\RegionContactService;
  7. use App\Util\StringToEntityUtil;
  8. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  9. class RegionContactListener extends FormSubmitEventListener
  10. {
  11.     private RegionContactService $service;
  12.     public function __construct(
  13.         MailerInterface $mailer,
  14.         ParameterBagInterface $parameterBag,
  15.         StringToEntityUtil $stringToEntityUtil,
  16.         RegionContactService $service,
  17.         Config $config
  18.     ) {
  19.         parent::__construct($mailer$parameterBag$stringToEntityUtilnull$config);
  20.         $this->service $service;
  21.     }
  22.     public function postContactSubmit(RegionContactSubmitEvent $event)
  23.     {
  24.         $contact $event->getContact();
  25.         $region $contact->getCompany() ? $this->service->fetchFilteredCompanyName($contact->getCompany()->getName()) : '';
  26.         if ($siteOwnerMail $this->getMail('site_region_contact_mail_site_owner')) {
  27.             // Set default recipient
  28.             $recipient $this->parameterBag->get('site_company_email_address');
  29.             // Check if company was provided in the Region Contact form and set the email address if so.
  30.             if ($contact->getCompany()) {
  31.                 $recipient $contact->getCompany()->getEmail() ?? $recipient;
  32.             }
  33.             // Last override, site_region_contact_single_recipient can be empty, then the company check above should be used
  34.             $recipient = !empty($this->parameterBag->get('site_region_contact_single_recipient')) ?
  35.                 $this->parameterBag->get('site_region_contact_single_recipient') : $recipient;
  36.             $this->mailer->mail(
  37.                 $siteOwnerMail,
  38.                 $this->getCompanyEmailSender(),
  39.                 [$recipient],
  40.                 ['contact' => $contact'region' => $region]
  41.             );
  42.         }
  43.         if ($visitorMail $this->getMail('site_region_contact_mail_visitor')) {
  44.             $this->mailer->mail(
  45.                 $visitorMail,
  46.                 $this->getCompanyEmailSender(),
  47.                 [$contact->getEmail()],
  48.                 ['contact' => $contact'region' => $region]
  49.             );
  50.         }
  51.     }
  52. }