Skip to content

Commit

Permalink
add adapter to update data sent from asset editor
Browse files Browse the repository at this point in the history
  • Loading branch information
lukmzig committed Dec 13, 2024
1 parent f1d1c68 commit 90b7d75
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/assets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Asset/Attribute/Request/UpdateAssetRequestBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
55 changes: 55 additions & 0 deletions src/Asset/Updater/Adapter/DataUriAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Asset\Updater\Adapter;

use Pimcore\Bundle\StudioBackendBundle\Updater\Adapter\UpdateAdapterInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementTypes;
use Pimcore\Model\Asset;
use Pimcore\Model\Element\ElementInterface;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;

/**
* @internal
*/
#[AutoconfigureTag('pimcore.studio_backend.update_adapter')]
final readonly class DataUriAdapter implements UpdateAdapterInterface
{
private const INDEX_KEY = 'dataUri';

public function update(ElementInterface $element, array $data): void
{
if (!$element instanceof Asset) {
return;
}

$assetData = $data[$this->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,
];
}
}

0 comments on commit 90b7d75

Please sign in to comment.