vendor/mrpix/cms-feed/src/Subscriber/PageSubscriber.php line 28

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Mrpix\CmsFeed\Subscriber;
  3. use Mrpix\CmsFeed\Services\StickyMenu;
  4. use Shopware\Storefront\Page\GenericPageLoadedEvent;
  5. use Shopware\Storefront\Page\PageLoadedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class PageSubscriber implements EventSubscriberInterface
  8. {
  9.     private StickyMenu $stickyMenuService;
  10.     public function __construct(StickyMenu $stickyMenuService)
  11.     {
  12.         $this->stickyMenuService $stickyMenuService;
  13.     }
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             GenericPageLoadedEvent::class => 'onPageLoaded',
  18.         ];
  19.     }
  20.     public function onPageLoaded(PageLoadedEvent $event): void
  21.     {
  22.         $stickyMenu $this->stickyMenuService->getStickyMenuEntires($event->getContext());
  23.         if (empty($stickyMenu)) {
  24.             return;
  25.         }
  26.         $page $event->getPage();
  27.         $page->addArrayExtension('stickyMenu'$stickyMenu);
  28.     }
  29. }