From 90b7d7586315e995c72e1445617d2644a157ddb5 Mon Sep 17 00:00:00 2001 From: lukmzig Date: Fri, 13 Dec 2024 11:16:15 +0100 Subject: [PATCH] add adapter to update data sent from asset editor --- config/assets.yaml | 3 + .../Request/UpdateAssetRequestBody.php | 1 + src/Asset/Updater/Adapter/DataUriAdapter.php | 55 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 src/Asset/Updater/Adapter/DataUriAdapter.php diff --git a/config/assets.yaml b/config/assets.yaml index f156a954b..8cb85b579 100644 --- a/config/assets.yaml +++ b/config/assets.yaml @@ -75,6 +75,9 @@ services: Pimcore\Bundle\StudioBackendBundle\Asset\Updater\Adapter\DataAdapter: tags: [ 'pimcore.studio_backend.update_adapter' ] + Pimcore\Bundle\StudioBackendBundle\Asset\Updater\Adapter\DataUriAdapter: + tags: [ 'pimcore.studio_backend.update_adapter' ] + # # Handler diff --git a/src/Asset/Attribute/Request/UpdateAssetRequestBody.php b/src/Asset/Attribute/Request/UpdateAssetRequestBody.php index fdb211047..855f3f8a8 100644 --- a/src/Asset/Attribute/Request/UpdateAssetRequestBody.php +++ b/src/Asset/Attribute/Request/UpdateAssetRequestBody.php @@ -47,6 +47,7 @@ public function __construct() new UpdateStringProperty('key'), new UpdateStringProperty('locked'), new UpdateStringProperty('data'), + new UpdateStringProperty('dataUri'), new UpdateCustomMetadata(), new UpdateCustomSettingsData(), new UpdateElementProperties(), diff --git a/src/Asset/Updater/Adapter/DataUriAdapter.php b/src/Asset/Updater/Adapter/DataUriAdapter.php new file mode 100644 index 000000000..c9fe65d15 --- /dev/null +++ b/src/Asset/Updater/Adapter/DataUriAdapter.php @@ -0,0 +1,55 @@ +getIndexKey()]; + $assetData = substr($assetData, strpos($assetData, ',')); + $element->setData(base64_decode($assetData)); + } + + public function getIndexKey(): string + { + return self::INDEX_KEY; + } + + public function supportedElementTypes(): array + { + return [ + ElementTypes::TYPE_ASSET, + ]; + } +}