vendor/coreshop/pimcore-bundle/EventListener/SluggableListener.php line 42

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * CoreShop
  5.  *
  6.  * This source file is available under two different licenses:
  7.  *  - GNU General Public License version 3 (GPLv3)
  8.  *  - CoreShop Commercial License (CCL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  * @copyright  Copyright (c) CoreShop GmbH (https://www.coreshop.org)
  13.  * @license    https://www.coreshop.org/license     GPLv3 and CCL
  14.  *
  15.  */
  16. namespace CoreShop\Bundle\PimcoreBundle\EventListener;
  17. use CoreShop\Component\Pimcore\Slug\DataObjectSlugGeneratorInterface;
  18. use CoreShop\Component\Pimcore\Slug\SluggableInterface;
  19. use Pimcore\Event\DataObjectEvents;
  20. use Pimcore\Event\Model\DataObjectEvent;
  21. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  22. final class SluggableListener implements EventSubscriberInterface
  23. {
  24.     public function __construct(
  25.         protected DataObjectSlugGeneratorInterface $generator,
  26.     ) {
  27.     }
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             DataObjectEvents::PRE_UPDATE => 'preUpdate',
  32.             DataObjectEvents::PRE_ADD => 'preUpdate',
  33.         ];
  34.     }
  35.     public function preUpdate(DataObjectEvent $dataObjectEvent): void
  36.     {
  37.         $object $dataObjectEvent->getObject();
  38.         if (!$object instanceof SluggableInterface) {
  39.             return;
  40.         }
  41.         $this->generator->generateSlugs($object);
  42.     }
  43. }