Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improvement] Add path to video #673

Merged
merged 7 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/DataObject/Data/Adapter/ManyToOneRelationAdapter.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\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;
Expand All @@ -25,14 +26,15 @@
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;

/**
* @internal
*/
#[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)]
final readonly class ManyToOneRelationAdapter implements SetterDataInterface
final readonly class ManyToOneRelationAdapter implements SetterDataInterface, DataNormalizerInterface
{
use ElementProviderTrait;

Expand All @@ -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;
}
}
26 changes: 24 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 @@ -26,14 +27,15 @@
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;

/**
* @internal
*/
#[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)]
final readonly class VideoAdapter implements SetterDataInterface
final readonly class VideoAdapter implements SetterDataInterface, DataNormalizerInterface
{
use ElementProviderTrait;

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,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;
}
}
Loading