vendor/store.shopware.com/dreiscseopro/src/Subscriber/CategoryEvents/CategoryLoadedSubscriber.php line 39

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace DreiscSeoPro\Subscriber\CategoryEvents;
  3. use DreiscSeoPro\Core\Seo\LiveTemplate\LiveTemplateConverter;
  4. use Shopware\Core\Content\Category\CategoryEntity;
  5. use Shopware\Core\Content\Category\CategoryEvents;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class CategoryLoadedSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var LiveTemplateConverter
  12.      */
  13.     private $liveTemplateConverter;
  14.     /**
  15.      * @param LiveTemplateConverter $liveTemplateConverter
  16.      */
  17.     public function __construct(LiveTemplateConverter $liveTemplateConverter)
  18.     {
  19.         $this->liveTemplateConverter $liveTemplateConverter;
  20.     }
  21.     /**
  22.      * @return array|void
  23.      */
  24.     public static function getSubscribedEvents()
  25.     {
  26.         return [
  27.             CategoryEvents::CATEGORY_LOADED_EVENT => 'onCategoryLoaded'
  28.         ];
  29.     }
  30.     /**
  31.      * @param EntityLoadedEvent $entityLoadedEvent
  32.      */
  33.     public function onCategoryLoaded(EntityLoadedEvent $entityLoadedEvent): void
  34.     {
  35.         /** @var CategoryEntity $categoryEntity */
  36.         $categoryEntity current($entityLoadedEvent->getEntities());
  37.         /** Abort, if empty */
  38.         if (false === $categoryEntity) {
  39.             return;
  40.         }
  41.         /** At this point the seo live template will be converted */
  42.         $this->liveTemplateConverter->translateCategoryEntity($categoryEntity$entityLoadedEvent->getContext());
  43.     }
  44. }