custom/plugins/GbmedForm/src/Storefront/MailService.php line 82

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * gb media
  4.  * All Rights Reserved.
  5.  *
  6.  * Unauthorized copying of this file, via any medium is strictly prohibited.
  7.  * The content of this file is proprietary and confidential.
  8.  *
  9.  * @category       Shopware
  10.  * @package        Shopware_Plugins
  11.  * @subpackage     GbmedForm
  12.  * @copyright      Copyright (c) 2020, gb media
  13.  * @license        proprietary
  14.  * @author         Giuseppe Bottino
  15.  * @link           http://www.gb-media.biz
  16.  */
  17. namespace Gbmed\Form\Storefront;
  18. use Gbmed\Form\Framework\Struct\GbmedFormStruct;
  19. use Shopware\Core\Content\Category\CategoryEntity;
  20. use Shopware\Core\Content\Category\Tree\Tree;
  21. use Shopware\Core\Content\Cms\CmsPageEntity;
  22. use Shopware\Core\Content\ContactForm\Event\ContactFormEvent;
  23. use Shopware\Core\Content\MailTemplate\Service\Event\MailBeforeSentEvent;
  24. use Shopware\Core\Framework\Context;
  25. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  26. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  27. use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
  28. use Shopware\Core\Framework\Struct\Struct;
  29. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
  30. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  31. use Shopware\Core\System\Salutation\SalutationCollection;
  32. use Shopware\Core\System\SystemConfig\SystemConfigService;
  33. use Shopware\Storefront\Page\Navigation\NavigationPage;
  34. use Shopware\Storefront\Page\Navigation\NavigationPageLoadedEvent;
  35. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  36. class MailService implements EventSubscriberInterface
  37. {
  38.     private $data = [];
  39.     private SystemConfigService $systemConfigService;
  40.     /**
  41.      * MailService constructor.
  42.      * @param SystemConfigService $systemConfigService
  43.      */
  44.     public function __construct(SystemConfigService $systemConfigService)
  45.     {
  46.         $this->systemConfigService $systemConfigService;
  47.     }
  48.     /**
  49.      * subscribed events
  50.      *
  51.      * @return array
  52.      */
  53.     public static function getSubscribedEvents(): array
  54.     {
  55.         return [
  56.             MailBeforeSentEvent::class => 'onMailBeforeSentEvent',
  57.             ContactFormEvent::EVENT_NAME => 'onContactFormEvent',
  58.         ];
  59.     }
  60.     /**
  61.      * @param MailBeforeSentEvent $event
  62.      */
  63.     public function onMailBeforeSentEvent(MailBeforeSentEvent $event): void
  64.     {
  65.         $mail $event->getMessage();
  66.         if (!$this->systemConfigService->getBool('GbmedForm.config.changeFrom') || !isset($this->data['email'])) {
  67.             return;
  68.         }
  69.         $mail->from($this->data['email']);
  70.     }
  71.     /**
  72.      * @param ContactFormEvent $event
  73.      */
  74.     public function onContactFormEvent(ContactFormEvent $event): void
  75.     {
  76.         $this->data $event->getContactFormData();
  77.     }
  78. }