<?php
declare(strict_types=1);
namespace WbfkThemeMMedientechnik\Subscriber;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Page\GenericPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class TopNavigationPageLoader implements EventSubscriberInterface
{
public function __construct(
private readonly SystemConfigService $systemConfigService,
#[Autowire(service: 'landing_page.repository')]
private readonly EntityRepository $landingPageRepository,
)
{
}
public static function getSubscribedEvents(): array
{
return [
GenericPageLoadedEvent::class => ['onGenericPageLoaded'],
];
}
public function onGenericPageLoaded(GenericPageLoadedEvent $event): void
{
$topNavigation = $this->systemConfigService->get('WbfkThemeMMedientechnik.config.topNavigation');
if ($topNavigation) {
$landingPages = $this->landingPageRepository->search(new Criteria($topNavigation), $event->getContext());
$page = $event->getPage();
$page->addExtension('preHeaderNavigation', $landingPages);
}
}
}