vendor/crehler/mojebambino-engine/src/Subscriber/FooterPageletSubscriber.php line 37

Open in your IDE?
  1. <?php
  2. namespace Crehler\MojeBambinoEngine\Subscriber;
  3. use Crehler\MojeBambinoEngine\Struct\FooterIconsGroupsStruct;
  4. use Crehler\MojeBambinoEngine\Struct\FooterIconsStruct;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  6. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  9. use Shopware\Core\Framework\Struct\ArrayEntity;
  10. use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. class FooterPageletSubscriber implements EventSubscriberInterface
  13. {
  14.     /** @var EntityRepository */
  15.     private $iconsRepository;
  16.     /** @var EntityRepository */
  17.     private $visibilityRepository;
  18.     public function __construct(EntityRepository $iconsRepositoryEntityRepository $visibilityRepository)
  19.     {
  20.         $this->iconsRepository $iconsRepository;
  21.         $this->visibilityRepository $visibilityRepository;
  22.     }
  23.     public static function getSubscribedEvents(): array
  24.     {
  25.         return [
  26.             FooterPageletLoadedEvent::class => 'addFooterIcons',
  27.         ];
  28.     }
  29.     public function addFooterIcons(FooterPageletLoadedEvent $event): void
  30.     {
  31.         $criteria = new Criteria();
  32.         $criteria->addFilter(new EqualsFilter('salesChannelId'$event->getSalesChannelContext()->getSalesChannel()->getId()))
  33.             ->addAssociation('icon');
  34.         /** @var \Shopware\Core\Framework\DataAbstractionLayer\Search\IdSearchResult $ids */
  35.         $entities $this->visibilityRepository->search($criteria$event->getContext());
  36. //dd($entities);
  37.         $iconsGroups = new FooterIconsGroupsStruct();
  38.         /** @var ArrayEntity $entity */
  39.         foreach ($entities as $entity) {
  40.             $iconEntity $entity->get('icon');
  41.             if ($iconEntity === null) continue;
  42.             $type $iconEntity->get('type');
  43.             $position = (int)$iconEntity->get('position');
  44.             $icon = (new FooterIconsStruct())
  45.                 ->setName(($iconEntity->getTranslation('name') !== null) ? $iconEntity->getTranslation('name') : $iconEntity->get('name'))
  46.                 ->setAlt(($iconEntity->getTranslation('alt') !== null) ? $iconEntity->getTranslation('alt') : $iconEntity->get('alt'))
  47.                 ->setUrl(($iconEntity->getTranslation('url') !== null) ? $iconEntity->getTranslation('url') : $iconEntity->get('url'))
  48.                 ->setMedia($iconEntity->get('media'))
  49.                 ->setTarget($iconEntity->get('target'));
  50.             if (!empty($iconEntity->get('rel'))) $icon->setRel($iconEntity->get('rel'));
  51.             switch ($type) {
  52.                 case 'social':
  53.                     $iconsGroups->addSocial($icon$position);
  54.                     break;
  55.                 case 'brands':
  56.                     $iconsGroups->addBrands($icon$position);
  57.                     break;
  58.             }
  59.         }
  60.         $iconsGroups->sort();
  61.         $event->getPagelet()->addExtension('footer_icons'$iconsGroups);
  62.     }
  63. }