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\Storefront\Page\Account\Order\AccountOrderPageLoadedEvent;
  5. use Shopware\Storefront\Page\Account\Overview\AccountOverviewPageLoadedEvent;
  6. use Shopware\Storefront\Page\Account\PaymentMethod\AccountPaymentMethodPageLoadedEvent;
  7. use Shopware\Storefront\Page\Account\Profile\AccountProfilePageLoadedEvent;
  8. use Shopware\Storefront\Page\Checkout\Finish\CheckoutFinishPageLoadedEvent;
  9. use Shopware\Storefront\Page\PageLoadedEvent;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class AccountSubscriber implements EventSubscriberInterface
  12. {
  13.     private FormService $formService;
  14.     public function __construct(
  15.         FormService $formService
  16.     )
  17.     {
  18.         $this->formService $formService;
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             AccountOverviewPageLoadedEvent::class => 'onAccountOverviewPageLoaded',
  24.             AccountProfilePageLoadedEvent::class => 'onAccountProfilePageLoaded',
  25.             AccountOrderPageLoadedEvent::class => 'onAccountOrderPageLoadedEvent',
  26.             AccountPaymentMethodPageLoadedEvent::class => 'onAccountPaymentMethodPageLoaded',
  27.             CheckoutFinishPageLoadedEvent::class => 'onCheckoutFinishPageLoaded'
  28.         ];
  29.     }
  30.     public function onAccountOverviewPageLoaded(PageLoadedEvent $event): void
  31.     {
  32.         $this->onAccountPageLoaded($event'customerAccountOverview');
  33.     }
  34.     public function onAccountProfilePageLoaded(PageLoadedEvent $event): void
  35.     {
  36.         $this->onAccountPageLoaded($event'customerAccountProfile');
  37.     }
  38.     public function onAccountOrderPageLoadedEvent(PageLoadedEvent $event): void
  39.     {
  40.         $this->onAccountPageLoaded($event'customerAccountOrder');
  41.     }
  42.     public function onAccountPaymentMethodPageLoaded(PageLoadedEvent $event): void
  43.     {
  44.         $this->onAccountPageLoaded($event'customerAccountPaymentMethod');
  45.     }
  46.     public function onCheckoutFinishPageLoaded(PageLoadedEvent $event): void
  47.     {
  48.         $this->onAccountPageLoaded($event'checkoutFinish');
  49.     }
  50.     private function onAccountPageLoaded(PageLoadedEvent $eventstring $type): void
  51.     {
  52.         $this->formService->setSalesChannelContext($event->getSalesChannelContext());
  53.         $this->formService->initFormsByType($event->getContext(), $type);
  54.         $this->formService->initCurrentForm();
  55.         if (!$this->formService->getCurrentForm()) {
  56.             return;
  57.         }
  58.         $event->getPage()->addExtension('MoorlFormBuilder'$this->formService->getCurrentForm());
  59.     }
  60. }