src/Core/Content/Media/Subscriber/MediaFolderConfigLoadedSubscriber.php line 29

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Media\Subscriber;
  3. use Shopware\Core\Content\Media\Aggregate\MediaFolderConfiguration\MediaFolderConfigurationEntity;
  4. use Shopware\Core\Content\Media\Aggregate\MediaThumbnailSize\MediaThumbnailSizeCollection;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  6. use Shopware\Core\Framework\Log\Package;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. /**
  9.  * @internal
  10.  */
  11. #[Package('content')]
  12. class MediaFolderConfigLoadedSubscriber implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  16.      */
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             'media_folder_configuration.loaded' => [
  21.                 ['unserialize'10],
  22.             ],
  23.         ];
  24.     }
  25.     public function unserialize(EntityLoadedEvent $event): void
  26.     {
  27.         /** @var MediaFolderConfigurationEntity $media */
  28.         foreach ($event->getEntities() as $media) {
  29.             if ($media->getMediaThumbnailSizes() === null) {
  30.                 if ($media->getMediaThumbnailSizesRo()) {
  31.                     $media->setMediaThumbnailSizes(unserialize($media->getMediaThumbnailSizesRo()));
  32.                 } else {
  33.                     $media->setMediaThumbnailSizes(new MediaThumbnailSizeCollection());
  34.                 }
  35.             }
  36.         }
  37.     }
  38. }