custom/plugins/WbfkThemeMMedientechnik/src/Subscriber/TopNavigationPageLoader.php line 37

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace WbfkThemeMMedientechnik\Subscriber;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\System\SystemConfig\SystemConfigService;
  7. use Shopware\Storefront\Page\GenericPageLoadedEvent;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class TopNavigationPageLoader implements EventSubscriberInterface
  10. {
  11.     public function __construct(
  12.         private readonly SystemConfigService $systemConfigService,
  13.         #[Autowire(service'landing_page.repository')]
  14.         private readonly EntityRepository $landingPageRepository,
  15.     )
  16.     {
  17.     }
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             GenericPageLoadedEvent::class => ['onGenericPageLoaded'],
  22.         ];
  23.     }
  24.     public function onGenericPageLoaded(GenericPageLoadedEvent $event): void
  25.     {
  26.         $topNavigation $this->systemConfigService->get('WbfkThemeMMedientechnik.config.topNavigation');
  27.         if ($topNavigation) {
  28.             $landingPages $this->landingPageRepository->search(new Criteria($topNavigation), $event->getContext());
  29.             $page $event->getPage();
  30.             $page->addExtension('preHeaderNavigation'$landingPages);
  31.         }
  32.     }
  33. }