Skip to content

Commit

Permalink
Add normalizer interface to video
Browse files Browse the repository at this point in the history
  • Loading branch information
mattamon committed Jan 13, 2025
1 parent acab670 commit 85fa003
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/DataObject/Data/Adapter/VideoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
}
Expand All @@ -49,7 +51,6 @@ public function getDataForSetter(
?FieldContextData $contextData = null
): ?Video {
$adapterData = $data[$key] ?? null;

if (!is_array($adapterData)) {
return null;
}
Expand Down Expand Up @@ -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);

Check failure on line 96 in src/DataObject/Data/Adapter/VideoAdapter.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, 11.x-dev as 11.99.9, true) / Static analysis with phpstan

Call to an undefined method Pimcore\Model\DataObject\ClassDefinition\Data::normalize().

Check failure on line 96 in src/DataObject/Data/Adapter/VideoAdapter.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.2, lowest, false) / Static analysis with phpstan

Call to an undefined method Pimcore\Model\DataObject\ClassDefinition\Data::normalize().

Check failure on line 96 in src/DataObject/Data/Adapter/VideoAdapter.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, false) / Static analysis with phpstan

Call to an undefined method Pimcore\Model\DataObject\ClassDefinition\Data::normalize().

if (isset($data['poster'])) {
$data['poster']['path'] = $value->getPoster()?->getRealFullPath();
}

if (isset($data['data'])) {
$data['data']['path'] = $value->getData()?->getRealFullPath();
}

return $data;
}
}

0 comments on commit 85fa003

Please sign in to comment.