custom/plugins/MoorlFormBuilder/src/Subscriber/AccountSubscriber.php line 46

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace MoorlFormBuilder\Subscriber;
  3. use MoorlFormBuilder\Core\Service\FormService;
  4. use Shopware\Core\Content\Cms\CmsPageEvents;
  5. use Shopware\Core\Content\Media\Event\MediaFileExtensionWhitelistEvent;
  6. use Shopware\Core\Framework\Api\Context\SalesChannelApiSource;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  8. use Shopware\Storefront\Page\Account\Order\AccountOrderPage;
  9. use Shopware\Storefront\Page\Account\Order\AccountOrderPageLoadedEvent;
  10. use Shopware\Storefront\Page\Account\Overview\AccountOverviewPageLoadedEvent;
  11. use Shopware\Storefront\Page\Account\PaymentMethod\AccountPaymentMethodPageLoadedEvent;
  12. use Shopware\Storefront\Page\Account\Profile\AccountProfilePageLoadedEvent;
  13. use Shopware\Storefront\Page\Checkout\Finish\CheckoutFinishPageLoadedEvent;
  14. use Shopware\Storefront\Page\PageLoadedEvent;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class AccountSubscriber implements EventSubscriberInterface
  17. {
  18.     private FormService $formService;
  19.     public function __construct(
  20.         FormService $formService
  21.     )
  22.     {
  23.         $this->formService $formService;
  24.     }
  25.     public static function getSubscribedEvents(): array
  26.     {
  27.         return [
  28.             AccountOverviewPageLoadedEvent::class => 'onAccountOverviewPageLoaded',
  29.             AccountProfilePageLoadedEvent::class => 'onAccountProfilePageLoaded',
  30.             AccountOrderPageLoadedEvent::class => 'onAccountOrderPageLoadedEvent',
  31.             AccountPaymentMethodPageLoadedEvent::class => 'onAccountPaymentMethodPageLoaded',
  32.             CheckoutFinishPageLoadedEvent::class => 'onCheckoutFinishPageLoaded'
  33.         ];
  34.     }
  35.     public function onAccountOverviewPageLoaded(PageLoadedEvent $event): void
  36.     {
  37.         $this->onAccountPageLoaded($event'customerAccountOverview');
  38.     }
  39.     public function onAccountProfilePageLoaded(PageLoadedEvent $event): void
  40.     {
  41.         $this->onAccountPageLoaded($event'customerAccountProfile');
  42.     }
  43.     public function onAccountOrderPageLoadedEvent(PageLoadedEvent $event): void
  44.     {
  45.         $this->onAccountPageLoaded($event'customerAccountOrder');
  46.     }
  47.     public function onAccountPaymentMethodPageLoaded(PageLoadedEvent $event): void
  48.     {
  49.         $this->onAccountPageLoaded($event'customerAccountPaymentMethod');
  50.     }
  51.     public function onCheckoutFinishPageLoaded(PageLoadedEvent $event): void
  52.     {
  53.         $this->onAccountPageLoaded($event'checkoutFinish');
  54.     }
  55.     private function onAccountPageLoaded(PageLoadedEvent $eventstring $type): void
  56.     {
  57.         $this->formService->setSalesChannelContext($event->getSalesChannelContext());
  58.         $this->formService->initFormsByType($event->getContext(), $type);
  59.         $this->formService->initCurrentForm();
  60.         if (!$this->formService->getCurrentForm()) {
  61.             return;
  62.         }
  63.         $event->getPage()->addExtension('MoorlFormBuilder'$this->formService->getCurrentForm());
  64.     }
  65. }