custom/plugins/RHWebThemeFeatures/src/Subscriber/CmsLoaderSubscriber.php line 40

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace RHWeb\ThemeFeatures\Subscriber;
  4. use Shopware\Core\Content\Cms\SalesChannel\SalesChannelCmsPageLoaderInterface;
  5. use Shopware\Core\Content\Cms\SalesChannel\SalesChannelCmsPageRepository;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Shopware\Storefront\Pagelet\Header\HeaderPageletLoadedEvent;
  9. use Shopware\Core\System\SystemConfig\SystemConfigService;
  10. class CmsLoaderSubscriber implements EventSubscriberInterface
  11. {
  12.     private $systemConfigService;
  13.     private $cmsPageRepository;
  14.     private $cmsPageLoader;
  15.     public function __construct(
  16.         SalesChannelCmsPageRepository $cmsPageRepository,
  17.         SystemConfigService $systemConfigService,
  18.         SalesChannelCmsPageLoaderInterface $cmsPageLoader)
  19.     {
  20.         $this->cmsPageRepository $cmsPageRepository;
  21.         $this->systemConfigService $systemConfigService;
  22.         $this->cmsPageLoader $cmsPageLoader;
  23.     }
  24.     public static function getSubscribedEvents(): array
  25.     {
  26.         return [
  27.             HeaderPageletLoadedEvent::class => 'getCmsPage'
  28.         ];
  29.     }
  30.     public function getCmsPage(HeaderPageletLoadedEvent $event): void
  31.     {
  32.         $request $event->getRequest();
  33.         $context $event->getSalesChannelContext();
  34.         $id $this->systemConfigService->get('RHWebThemeFeatures.config.RhwebThemeFeaturesExitIntentCmsPageId');
  35.         if($id != ''){
  36.             $criteria = new Criteria([$id]);
  37.             $pages $this->cmsPageLoader->load($request$criteria$context);
  38.             $event->getPagelet()->assign([
  39.                 'RHWebCmsPage' => $pages->get($id)
  40.             ]);
  41.         }
  42.     }
  43. }