From 4d2cb3abe057d3989eb6fce2b69423ce611ec8c9 Mon Sep 17 00:00:00 2001 From: Martin Eiber Date: Tue, 3 Dec 2024 10:40:55 +0100 Subject: [PATCH] [Data Object Editor] Field-Collections with block and localized fields not working (#609) * localized fields adapter not returning values * Add context to getFieldDefinition(). * Null check. * Remove roave/security-advisories --------- Co-authored-by: lukmzig --- composer.json | 1 - .../Data/Adapter/LocalizedFieldsAdapter.php | 12 ++++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 6d6827e2..73519c1f 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,6 @@ }, "require-dev": { "pimcore/admin-ui-classic-bundle": "^v1.3", - "roave/security-advisories": "dev-latest", "codeception/codeception": "^5.0.10", "codeception/phpunit-wrapper": "^9", "codeception/module-asserts": "^2", diff --git a/src/DataObject/Data/Adapter/LocalizedFieldsAdapter.php b/src/DataObject/Data/Adapter/LocalizedFieldsAdapter.php index fa2ce28c..ac48fd36 100644 --- a/src/DataObject/Data/Adapter/LocalizedFieldsAdapter.php +++ b/src/DataObject/Data/Adapter/LocalizedFieldsAdapter.php @@ -26,6 +26,7 @@ use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateFieldTypeTrait; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementPermissions; use Pimcore\Model\DataObject\ClassDefinition\Data; @@ -111,6 +112,9 @@ public function normalize( $value->loadLazyData(); $originalValue = $fieldDefinition->normalize($value); + if ($originalValue === null) { + return null; + } $languages = array_keys($originalValue); $attributes = array_keys(reset($originalValue)); $result = []; @@ -126,8 +130,12 @@ public function normalize( ) ); } - $fieldDefinition = $value->getFieldDefinition($attribute); - $localizedValue = $this->dataService->getNormalizedValue($localizedValue, $fieldDefinition); + $fieldDefinition = $value->getFieldDefinition($attribute, $value->getContext()); + if ($fieldDefinition === null) { + throw new NotFoundException(type: 'Field Definition', id: $attribute); + } + + $localizedValue = $this->dataService->getNormalizedValue($localizedValue, $fieldDefinition); $result[$attribute][$language] = $localizedValue; } }