<?php declare(strict_types=1);
namespace Mrpix\CmsFeed\Subscriber;
use Mrpix\CmsFeed\Services\StickyMenu;
use Shopware\Storefront\Page\GenericPageLoadedEvent;
use Shopware\Storefront\Page\PageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PageSubscriber implements EventSubscriberInterface
{
private StickyMenu $stickyMenuService;
public function __construct(StickyMenu $stickyMenuService)
{
$this->stickyMenuService = $stickyMenuService;
}
public static function getSubscribedEvents(): array
{
return [
GenericPageLoadedEvent::class => 'onPageLoaded',
];
}
public function onPageLoaded(PageLoadedEvent $event): void
{
$stickyMenu = $this->stickyMenuService->getStickyMenuEntires($event->getContext());
if (empty($stickyMenu)) {
return;
}
$page = $event->getPage();
$page->addArrayExtension('stickyMenu', $stickyMenu);
}
}