vendor/store.shopware.com/h1webblog/src/Subscriber/BlogSubscriber.php line 41

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace H1web\Blog\Subscriber;
  3. use Shopware\Core\Content\Category\CategoryEntity;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Shopware\Core\Content\Category\CategoryEvents;
  7. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  9. use Shopware\Core\System\Tag\TagEntity;
  10. use H1web\Blog\Helper\BlogHelper;
  11. class BlogSubscriber implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @var EntityRepositoryInterface
  15.      */
  16.     private $blogRepository;
  17.     /**
  18.      * @var BlogHelper
  19.      */
  20.     private $blogHelper;
  21.     public function __construct(
  22.         EntityRepositoryInterface $blogRepository,
  23.         BlogHelper $blogHelper
  24.     ) {
  25.         $this->blogRepository $blogRepository;
  26.         $this->blogHelper $blogHelper;
  27.     }
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             'tag.loaded' => 'onTagLoaded',
  32.         ];
  33.     }
  34.     public function onTagLoaded(EntityLoadedEvent $event): void
  35.     {
  36.         $context $event->getContext();
  37.         /** @var TagEntity $tagEntity */
  38.         foreach ($event->getEntities() as $tagEntity) {
  39.             $tagEntity->addExtension('blogOverviewUrl',
  40.                 $this->blogHelper->getTagOverviewUrl($tagEntity->getId(), $context)
  41.             );
  42.         }
  43.     }
  44. }