<?php declare(strict_types=1);
namespace Shopware\Core\Content\Media\Subscriber;
use Shopware\Core\Content\Media\Aggregate\MediaFolderConfiguration\MediaFolderConfigurationEntity;
use Shopware\Core\Content\Media\Aggregate\MediaThumbnailSize\MediaThumbnailSizeCollection;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
*/
class MediaFolderConfigLoadedSubscriber implements EventSubscriberInterface
{
/**
* @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
*/
public static function getSubscribedEvents()
{
return [
'media_folder_configuration.loaded' => [
['unserialize', 10],
],
];
}
public function unserialize(EntityLoadedEvent $event): void
{
/** @var MediaFolderConfigurationEntity $media */
foreach ($event->getEntities() as $media) {
if ($media->getMediaThumbnailSizes() === null) {
if ($media->getMediaThumbnailSizesRo()) {
$media->setMediaThumbnailSizes(unserialize($media->getMediaThumbnailSizesRo()));
} else {
$media->setMediaThumbnailSizes(new MediaThumbnailSizeCollection());
}
}
}
}
}