diff --git a/src/DataObject/Data/Adapter/ManyToOneRelationAdapter.php b/src/DataObject/Data/Adapter/ManyToOneRelationAdapter.php index 5a93423b..61fe3fb9 100644 --- a/src/DataObject/Data/Adapter/ManyToOneRelationAdapter.php +++ b/src/DataObject/Data/Adapter/ManyToOneRelationAdapter.php @@ -17,6 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface; +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; @@ -25,6 +26,7 @@ use Pimcore\Model\DataObject\ClassDefinition\Data; use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\Element\ElementInterface; +use Pimcore\Normalizer\NormalizerInterface; use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; use function is_array; @@ -32,7 +34,7 @@ * @internal */ #[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)] -final readonly class ManyToOneRelationAdapter implements SetterDataInterface +final readonly class ManyToOneRelationAdapter implements SetterDataInterface, DataNormalizerInterface { use ElementProviderTrait; @@ -59,4 +61,20 @@ public function getDataForSetter( return null; } } + + public function normalize(mixed $value, Data $fieldDefinition): mixed + { + if (!$fieldDefinition instanceof NormalizerInterface) { + return null; + } + + $data = $fieldDefinition->normalize($value); + + if (!empty($data)) { + $data['fullPath'] = $value->getRealFullPath(); + $data['subtype'] = $value->getType(); + } + + return $data; + } } diff --git a/src/DataObject/Data/Adapter/VideoAdapter.php b/src/DataObject/Data/Adapter/VideoAdapter.php index fc020d11..535c8ba5 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; @@ -26,6 +27,7 @@ use Pimcore\Model\DataObject\ClassDefinition\Data; use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\DataObject\Data\Video; +use Pimcore\Normalizer\NormalizerInterface; use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; use function is_array; @@ -33,7 +35,7 @@ * @internal */ #[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)] -final readonly class VideoAdapter implements SetterDataInterface +final readonly class VideoAdapter implements SetterDataInterface, DataNormalizerInterface { use ElementProviderTrait; @@ -49,7 +51,6 @@ public function getDataForSetter( ?FieldContextData $contextData = null ): ?Video { $adapterData = $data[$key] ?? null; - if (!is_array($adapterData)) { return null; } @@ -85,4 +86,25 @@ 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 || !$fieldDefinition instanceof NormalizerInterface) { + return null; + } + + $data = $fieldDefinition->normalize($value); + + if (isset($data['poster'])) { + $data['poster']['fullPath'] = $value->getPoster()?->getRealFullPath(); + } + + if (isset($data['data'])) { + $data['data']['fullPath'] = $value->getData()?->getRealFullPath(); + $data['data']['subtype'] = $value->getData()?->getType(); + } + + return $data; + } }