diff --git a/src/DataObject/Data/Adapter/EncryptedFieldAdapter.php b/src/DataObject/Data/Adapter/EncryptedFieldAdapter.php index c150709c..15431bad 100644 --- a/src/DataObject/Data/Adapter/EncryptedFieldAdapter.php +++ b/src/DataObject/Data/Adapter/EncryptedFieldAdapter.php @@ -16,10 +16,12 @@ 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; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterServiceInterface; +use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataServiceInterface; use Pimcore\Model\DataObject\ClassDefinition\Data; use Pimcore\Model\DataObject\ClassDefinition\Data\EncryptedField as EncryptedFieldDefinition; use Pimcore\Model\DataObject\Concrete; @@ -30,10 +32,11 @@ * @internal */ #[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)] -final readonly class EncryptedFieldAdapter implements SetterDataInterface +final readonly class EncryptedFieldAdapter implements SetterDataInterface, DataNormalizerInterface { public function __construct( - private DataAdapterServiceInterface $dataAdapterService + private DataAdapterServiceInterface $dataAdapterService, + private DataServiceInterface $dataService ) { } @@ -63,6 +66,25 @@ public function getDataForSetter( ); } + public function normalize( + mixed $value, + Data $fieldDefinition + ): mixed { + if (!$fieldDefinition instanceof EncryptedFieldDefinition) { + return null; + } + + if (!$value instanceof EncryptedField) { + return $value; + } + + $plainValue = $value->getPlain(); + $delegateFieldDefinition = $fieldDefinition->getDelegate(); + + return $this->dataService->getNormalizedValue($plainValue, $delegateFieldDefinition) + ?? $plainValue; + } + private function handleDelegatedField( Concrete $element, Data $delegateFieldDefinition,