vendor/ibexa/connector-dam/src/lib/Event/PublishAssetEventDispatcher.php line 34

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace Ibexa\Connector\Dam\Event;
  8. use Ibexa\Contracts\Connector\Dam\AssetIdentifier;
  9. use Ibexa\Contracts\Connector\Dam\AssetSource;
  10. use Ibexa\Contracts\Core\Repository\Events\Content\PublishVersionEvent;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  13. final class PublishAssetEventDispatcher implements EventSubscriberInterface
  14. {
  15.     /** @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface */
  16.     private $eventDispatcher;
  17.     public function __construct(EventDispatcherInterface $eventDispatcher)
  18.     {
  19.         $this->eventDispatcher $eventDispatcher;
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             PublishVersionEvent::class => 'emitPublishAssetEvent',
  25.         ];
  26.     }
  27.     public function emitPublishAssetEvent(PublishVersionEvent $event)
  28.     {
  29.         $content $event->getContent();
  30.         foreach ($content->getFields() as $field) {
  31.             if ($field->fieldTypeIdentifier !== 'ezimageasset') {
  32.                 continue;
  33.             }
  34.             /** @var \Ibexa\Connector\Dam\FieldType\Dam\Value $value */
  35.             $value $field->value;
  36.             if ($value->source === null) {
  37.                 continue;
  38.             }
  39.             $this->eventDispatcher->dispatch(
  40.                 new PublishAssetEvent(
  41.                     $content,
  42.                     new AssetIdentifier($value->destinationContentId),
  43.                     new AssetSource($value->source)
  44.                 )
  45.             );
  46.         }
  47.     }
  48. }
  49. class_alias(PublishAssetEventDispatcher::class, 'Ibexa\Platform\Connector\Dam\Event\PublishAssetEventDispatcher');