Skip to content

Commit

Permalink
adjust additional adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
lukmzig committed Nov 28, 2024
1 parent b1a54ab commit 0347bb1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/DataObject/Data/Adapter/FieldCollectionsAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
final readonly class FieldCollectionsAdapter implements SetterDataInterface, DataNormalizerInterface
{
use ValidateFieldTypeTrait;
private const TYPE_KEY = 'type';
private const DATA_KEY = 'data';

public function __construct(
private DataAdapterServiceInterface $dataAdapterService,
Expand Down Expand Up @@ -72,7 +74,7 @@ public function getDataForSetter(
$collection = $this->createCollection(
$element,
$fieldDefinition,
$collectionRaw['type'],
$collectionRaw[self::TYPE_KEY],
$collectionData,
$count
);
Expand Down Expand Up @@ -100,15 +102,13 @@ public function normalize(
if (!$fieldCollectionDefinition) {
continue;
}
$resultItem = ['type' => $type];
$resultItem = [self::TYPE_KEY => $type, self::DATA_KEY => []];

foreach ($fieldCollectionDefinition->getFieldDefinitions() as $collectionFieldDefinition) {
$getter = 'get' . ucfirst($collectionFieldDefinition->getName());
$value = $item->$getter();
$resultItem[$collectionFieldDefinition->getName()] = $this->dataService->getNormalizedValue(
$value,
$collectionFieldDefinition,
);
$resultItem[self::DATA_KEY][$collectionFieldDefinition->getName()] =
$this->dataService->getNormalizedValue($value, $collectionFieldDefinition);
}

$resultItems[] = $resultItem;
Expand Down
15 changes: 14 additions & 1 deletion src/DataObject/Data/Adapter/RgbaColorAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter;

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 @@ -28,7 +29,7 @@
* @internal
*/
#[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)]
final readonly class RgbaColorAdapter implements SetterDataInterface
final readonly class RgbaColorAdapter implements SetterDataInterface, DataNormalizerInterface
{
public function getDataForSetter(
Concrete $element,
Expand All @@ -43,4 +44,16 @@ public function getDataForSetter(

return new RgbaColor($r, $g, $b, $a);
}

public function normalize(
mixed $value,
Data $fieldDefinition
): ?string
{
if (!$value instanceof RgbaColor) {
return null;
}

return $value->getHex(true);
}
}

0 comments on commit 0347bb1

Please sign in to comment.