vendor/pimcore/pimcore/bundles/CoreBundle/EventListener/ElementTagsListener.php line 64

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Bundle\CoreBundle\EventListener;
  15. use Pimcore\Event\AssetEvents;
  16. use Pimcore\Event\DataObjectEvents;
  17. use Pimcore\Event\DocumentEvents;
  18. use Pimcore\Event\Model\AssetEvent;
  19. use Pimcore\Event\Model\ElementEventInterface;
  20. use Pimcore\Model\Element\Service;
  21. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  22. /**
  23.  * @internal
  24.  */
  25. class ElementTagsListener implements EventSubscriberInterface
  26. {
  27.     /**
  28.      * {@inheritdoc}
  29.      */
  30.     public static function getSubscribedEvents(): array
  31.     {
  32.         return [
  33.             DataObjectEvents::POST_COPY => 'onPostCopy',
  34.             DocumentEvents::POST_COPY => 'onPostCopy',
  35.             AssetEvents::POST_COPY => 'onPostCopy',
  36.             AssetEvents::POST_DELETE => ['onPostAssetDelete', -9999],
  37.         ];
  38.     }
  39.     /**
  40.      * @param ElementEventInterface $e
  41.      */
  42.     public function onPostCopy(ElementEventInterface $e)
  43.     {
  44.         $elementType Service::getElementType($e->getElement());
  45.         $copiedElement $e->getElement();
  46.         /** @var \Pimcore\Model\Element\ElementInterface $baseElement */
  47.         $baseElement $e->getArgument('base_element');
  48.         \Pimcore\Model\Element\Tag::setTagsForElement(
  49.             $elementType,
  50.             $copiedElement->getId(),
  51.             \Pimcore\Model\Element\Tag::getTagsForElement($elementType$baseElement->getId())
  52.         );
  53.     }
  54.     /**
  55.      * @param AssetEvent $e
  56.      */
  57.     public function onPostAssetDelete(AssetEvent $e)
  58.     {
  59.         $asset $e->getAsset();
  60.         \Pimcore\Model\Element\Tag::setTagsForElement('asset'$asset->getId(), []);
  61.     }
  62. }