custom/plugins/AcrisFaqCS/src/Storefront/Framework/Seo/SeoUrlRoute/FaqSeoUrlUpdateListener.php line 49

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Acris\Faq\Storefront\Framework\Seo\SeoUrlRoute;
  3. use Acris\Faq\Core\Content\Faq\DataAbstractionLayer\FaqIndexerEvent;
  4. use Doctrine\DBAL\Connection;
  5. use Shopware\Core\Content\Seo\SeoUrlUpdater;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenContainerEvent;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Indexing\EntityIndexerRegistry;
  8. use Shopware\Core\System\SalesChannel\SalesChannelDefinition;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. class FaqSeoUrlUpdateListener implements EventSubscriberInterface
  11. {
  12.     private SeoUrlUpdater $seoUrlUpdater;
  13.     private Connection $connection;
  14.     private EntityIndexerRegistry $indexerRegistry;
  15.     public function __construct(SeoUrlUpdater $seoUrlUpdaterConnection $connectionEntityIndexerRegistry $indexerRegistry)
  16.     {
  17.         $this->seoUrlUpdater $seoUrlUpdater;
  18.         $this->connection $connection;
  19.         $this->indexerRegistry $indexerRegistry;
  20.     }
  21.     public function detectSalesChannelEntryPoints(EntityWrittenContainerEvent $event): void
  22.     {
  23.         $properties = ['navigationCategoryId''footerCategoryId''serviceCategoryId'];
  24.         $salesChannelIds $event->getPrimaryKeysWithPropertyChange(SalesChannelDefinition::ENTITY_NAME$properties);
  25.         if (empty($salesChannelIds)) {
  26.             return;
  27.         }
  28.         $this->indexerRegistry->sendIndexingMessage(['acris_faq.indexer']);
  29.     }
  30.     public static function getSubscribedEvents()
  31.     {
  32.         return [
  33.             FaqIndexerEvent::class => 'updateFaqUrls',
  34.             EntityWrittenContainerEvent::class => 'detectSalesChannelEntryPoints',
  35.         ];
  36.     }
  37.     public function updateFaqUrls(FaqIndexerEvent $event): void
  38.     {
  39.         $ids $event->getIds();
  40.         $this->seoUrlUpdater->update(FaqPageSeoUrlRoute::ROUTE_NAME$ids);
  41.     }
  42. }