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

[Image Editor] Add adapter to update data sent from asset editor #641

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