|
17 | 17 | namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter; |
18 | 18 |
|
19 | 19 | use Exception; |
| 20 | +use InvalidArgumentException; |
20 | 21 | use Pimcore\Bundle\StaticResolverBundle\Lib\ToolResolverInterface; |
21 | 22 | use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\DataInheritanceInterface; |
22 | 23 | use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\DataNormalizerInterface; |
| 24 | +use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\BlockData; |
23 | 25 | use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData; |
24 | 26 | use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SearchPreviewDataInterface; |
25 | 27 | use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; |
|
29 | 31 | use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\InheritanceServiceInterface; |
30 | 32 | use Pimcore\Bundle\StudioBackendBundle\DataObject\Util\Trait\ValidateObjectDataTrait; |
31 | 33 | use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException; |
32 | | -use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; |
33 | 34 | use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; |
34 | 35 | use Pimcore\Bundle\StudioBackendBundle\Security\Service\LanguageServiceInterface; |
35 | 36 | use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; |
@@ -86,7 +87,6 @@ public function getDataForSetter( |
86 | 87 |
|
87 | 88 | $languageData = $this->getAllowedLanguages($element, $user, $data[$key]); |
88 | 89 | $localizedField = $this->getLocalizedField($contextData, $element); |
89 | | - $localizedField->setObject($element); |
90 | 90 |
|
91 | 91 | foreach ($languageData as $name => $localizedData) { |
92 | 92 | foreach ($localizedData as $language => $fieldData) { |
@@ -292,17 +292,27 @@ private function getPreviewLanguage(Localizedfield $value): ?string |
292 | 292 | */ |
293 | 293 | private function getLocalizedField(?FieldContextData $contextData, Concrete $element): Localizedfield |
294 | 294 | { |
| 295 | + $contextObject = $contextData?->getContextObject(); |
| 296 | + $localizedField = null; |
| 297 | + |
295 | 298 | if ($contextData === null) { |
296 | | - $localizedField = $this->getValidFieldValue($element, self::LOCALIZED_FIELDS_KEY); |
297 | | - if (!$localizedField instanceof Localizedfield) { |
298 | | - return new Localizedfield(); |
299 | | - } |
| 299 | + $localizedField = $this->getValidFieldValue($element, self::LOCALIZED_FIELDS_KEY); |
| 300 | + } |
300 | 301 |
|
301 | | - return $localizedField; |
| 302 | + if ($contextObject !== null) { |
| 303 | + $localizedField = $contextData->getFieldValueFromContextObject(self::LOCALIZED_FIELDS_KEY); |
| 304 | + if (!$localizedField && $contextObject instanceof BlockData) { |
| 305 | + $localizedField = new Localizedfield(); |
| 306 | + $localizedField->setContext( |
| 307 | + $contextObject->getContextData() |
| 308 | + ); |
| 309 | + } |
302 | 310 | } |
303 | 311 |
|
304 | | - if ($contextData->getContextObject() !== null) { |
305 | | - return $contextData->getFieldValueFromContextObject(self::LOCALIZED_FIELDS_KEY); |
| 312 | + if ($localizedField) { |
| 313 | + $localizedField->setObject($element); |
| 314 | + |
| 315 | + return $localizedField; |
306 | 316 | } |
307 | 317 |
|
308 | 318 | throw new InvalidArgumentException('Invalid context provided.'); |
|
0 commit comments