custom/plugins/theme/src/Subscriber/FooterPageletLoadedSubscriber.php line 35

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace DonCarneTheme\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Shopware\Core\Framework\Struct\ArrayStruct;
  5. use Shopware\Core\System\SystemConfig\SystemConfigService;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  8. use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
  9. class FooterPageletLoadedSubscriber implements EventSubscriberInterface
  10. {
  11.     private SystemConfigService $systemConfigService;
  12.     private EntityRepositoryInterface $mediaRepository;
  13.     public function __construct(
  14.         SystemConfigService $systemConfigService,
  15.         EntityRepositoryInterface $mediaRepository
  16.     ){
  17.         $this->systemConfigService $systemConfigService;
  18.         $this->mediaRepository $mediaRepository;
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             FooterPageletLoadedEvent::class => 'addConfigData'
  24.         ];
  25.     }
  26.     /**
  27.      * Loads social media and quality certificate images. links can be taken directly in template
  28.      */
  29.     public function addConfigData(FooterPageletLoadedEvent $event)
  30.     {
  31.         $themeConfig $this->systemConfigService->get("DonCarneTheme.config");
  32.        if(!$themeConfig){
  33.            return;
  34.        }
  35.         $qualityIconArr array_filter($themeConfig, function($key){
  36.             return str_starts_with($key"qualityCertImage");
  37.         }, ARRAY_FILTER_USE_KEY);
  38.         $socialMediaIconArr array_filter($themeConfig, function($key){
  39.             return str_starts_with($key"socialMediaImage");
  40.         }, ARRAY_FILTER_USE_KEY);
  41.         // merge arrays
  42.         $mediaIds array_merge($qualityIconArr$socialMediaIconArr);
  43.         // remove empty values
  44.         $mediaIds array_filter($mediaIds);
  45.         //load images
  46.         $criteria = new Criteria($mediaIds);
  47.         $mediaCollection $this->mediaRepository
  48.             ->search($criteria$event->getContext())
  49.             ->getEntities();
  50.         $mediaArr $mediaCollection->getElements();
  51.         $event->getPagelet()->addExtension('footerThemeConfigMedia', new ArrayStruct($mediaArr));
  52.     }
  53. }