platform/src/Core/Content/Media/Subscriber/MediaFolderConfigLoadedSubscriber.php line 21

Open in your IDE?
  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 Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class MediaFolderConfigLoadedSubscriber implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents()
  10.     {
  11.         return [
  12.             'media_folder_configuration.loaded' => [
  13.                 ['unserialize'10],
  14.             ],
  15.         ];
  16.     }
  17.     public function unserialize(EntityLoadedEvent $event): void
  18.     {
  19.         /** @var MediaFolderConfigurationEntity $media */
  20.         foreach ($event->getEntities() as $media) {
  21.             if ($media->getMediaThumbnailSizes() === null) {
  22.                 if ($media->getMediaThumbnailSizesRo()) {
  23.                     $media->setMediaThumbnailSizes(unserialize($media->getMediaThumbnailSizesRo()));
  24.                 } else {
  25.                     $media->setMediaThumbnailSizes(new MediaThumbnailSizeCollection());
  26.                 }
  27.             }
  28.         }
  29.     }
  30. }