From 85fa0038c938cd5b1023c63318dec414ca2a8ac8 Mon Sep 17 00:00:00 2001 From: mattamon Date: Mon, 13 Jan 2025 08:38:15 +0100 Subject: [PATCH] Add normalizer interface to video --- src/DataObject/Data/Adapter/VideoAdapter.php | 24 ++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/DataObject/Data/Adapter/VideoAdapter.php b/src/DataObject/Data/Adapter/VideoAdapter.php index fc020d11..b80b3248 100644 --- a/src/DataObject/Data/Adapter/VideoAdapter.php +++ b/src/DataObject/Data/Adapter/VideoAdapter.php @@ -17,6 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; use Pimcore\Bundle\StaticResolverBundle\Models\Asset\AssetResolverInterface; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\DataNormalizerInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; @@ -33,10 +34,11 @@ * @internal */ #[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)] -final readonly class VideoAdapter implements SetterDataInterface +final readonly class VideoAdapter implements SetterDataInterface, DataNormalizerInterface { use ElementProviderTrait; + public function __construct(private AssetResolverInterface $assetResolver) { } @@ -49,7 +51,6 @@ public function getDataForSetter( ?FieldContextData $contextData = null ): ?Video { $adapterData = $data[$key] ?? null; - if (!is_array($adapterData)) { return null; } @@ -85,4 +86,23 @@ private function getAssetByPath(?string $path): ?Asset { return $path ? $this->assetResolver->getByPath($path) : null; } + + public function normalize(mixed $value, Data $fieldDefinition): mixed + { + if (!$value instanceof Video) { + return null; + } + + $data = $fieldDefinition->normalize($value); + + if (isset($data['poster'])) { + $data['poster']['path'] = $value->getPoster()?->getRealFullPath(); + } + + if (isset($data['data'])) { + $data['data']['path'] = $value->getData()?->getRealFullPath(); + } + + return $data; + } }