vendor/crehler/mojebambino-catalog/src/Subscriber/SystemConfigWritten.php line 34

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * @copyright 2020 Crehler Sp. z o. o.
  5.  * @link https://crehler.com/
  6.  * @support support@crehler.com
  7.  *
  8.  * @author Mateusz FlasiƄski
  9.  *
  10.  * For the full copyright and license information, please view the LICENSE
  11.  * file that was distributed with this source code.
  12.  */
  13. namespace Crehler\Catalog\Subscriber;
  14. use Crehler\Catalog\Service\Seo\SeoUrlTemplateManager;
  15. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. class SystemConfigWritten implements EventSubscriberInterface
  18. {
  19.     private SeoUrlTemplateManager $seoUrlTemplateManager;
  20.     public function __construct(SeoUrlTemplateManager $seoUrlTemplateManager)
  21.     {
  22.         $this->seoUrlTemplateManager $seoUrlTemplateManager;
  23.     }
  24.     public static function getSubscribedEvents()
  25.     {
  26.         return ['system_config.written' => 'onConfigWritten'];
  27.     }
  28.     public function onConfigWritten(EntityWrittenEvent $event): void
  29.     {
  30.         foreach ($event->getWriteResults() as $entityWriteResult) {
  31.             if (!isset($entityWriteResult->getPayload()['configurationKey'])) {
  32.                 return;
  33.             }
  34.             if (!isset($entityWriteResult->getPayload()['configurationValue'])) {
  35.                 return;
  36.             }
  37.             if (strpos($entityWriteResult->getPayload()['configurationKey'], 'CrehlerCatalog.config.seo') === false) {
  38.                 continue;
  39.             }
  40.             $this->seoUrlTemplateManager->writeTemplateFromConfigKey($entityWriteResult->getPayload()['configurationKey'], $entityWriteResult->getPayload()['configurationValue']);
  41.         }
  42.     }
  43. }