<?php declare(strict_types=1);
namespace H1web\Blog\Subscriber;
use Shopware\Core\Content\Category\CategoryEntity;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\Content\Category\CategoryEvents;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\System\Tag\TagEntity;
use H1web\Blog\Helper\BlogHelper;
class BlogSubscriber implements EventSubscriberInterface
{
/**
* @var EntityRepositoryInterface
*/
private $blogRepository;
/**
* @var BlogHelper
*/
private $blogHelper;
public function __construct(
EntityRepositoryInterface $blogRepository,
BlogHelper $blogHelper
) {
$this->blogRepository = $blogRepository;
$this->blogHelper = $blogHelper;
}
public static function getSubscribedEvents(): array
{
return [
'tag.loaded' => 'onTagLoaded',
];
}
public function onTagLoaded(EntityLoadedEvent $event): void
{
$context = $event->getContext();
/** @var TagEntity $tagEntity */
foreach ($event->getEntities() as $tagEntity) {
$tagEntity->addExtension('blogOverviewUrl',
$this->blogHelper->getTagOverviewUrl($tagEntity->getId(), $context)
);
}
}
}