|
30 | 30 | use Pimcore\Normalizer\NormalizerInterface; |
31 | 31 | use Pimcore\Tool\Serialize; |
32 | 32 |
|
33 | | -class Block extends Data implements CustomResourcePersistingInterface, ResourcePersistenceAwareInterface, LazyLoadingSupportInterface, TypeDeclarationSupportInterface, VarExporterInterface, NormalizerInterface, DataContainerAwareInterface, PreGetDataInterface, PreSetDataInterface, FieldDefinitionEnrichmentModelInterface |
| 33 | +class Block extends Data implements CustomResourcePersistingInterface, ResourcePersistenceAwareInterface, LazyLoadingSupportInterface, TypeDeclarationSupportInterface, VarExporterInterface, NormalizerInterface, DataContainerAwareInterface, IdRewriterInterface, PreGetDataInterface, PreSetDataInterface, FieldDefinitionEnrichmentModelInterface |
34 | 34 | { |
35 | 35 | use DataObject\Traits\ClassSavedTrait; |
36 | 36 | use DataObject\Traits\FieldDefinitionEnrichmentDataTrait; |
@@ -468,6 +468,44 @@ public function getDiffVersionPreview(?array $data, ?Concrete $object = null, ar |
468 | 468 | return $value; |
469 | 469 | } |
470 | 470 |
|
| 471 | + public function rewriteIds(mixed $container, array $idMapping, array $params = []): mixed |
| 472 | + { |
| 473 | + $data = $this->getDataFromObjectParam($container, $params); |
| 474 | + |
| 475 | + if (is_array($data)) { |
| 476 | + foreach ($data as $item) { |
| 477 | + if (!is_array($item)) { |
| 478 | + continue; |
| 479 | + } |
| 480 | + |
| 481 | + foreach ($this->getFieldDefinitions() as $fieldDefinition) { |
| 482 | + if (!$fieldDefinition instanceof IdRewriterInterface) { |
| 483 | + continue; |
| 484 | + } |
| 485 | + |
| 486 | + $blockElement = $item[$fieldDefinition->getName()] ?? null; |
| 487 | + if (!$blockElement instanceof DataObject\Data\BlockElement) { |
| 488 | + continue; |
| 489 | + } |
| 490 | + |
| 491 | + $blockElement->setData( |
| 492 | + $fieldDefinition->rewriteIds( |
| 493 | + $container, |
| 494 | + $idMapping, |
| 495 | + [ |
| 496 | + ...$params, |
| 497 | + // \Pimcore\Model\DataObject\ClassDefinition\Data::getDataFromObjectParam() reads 'injectedData' |
| 498 | + 'injectedData' => $blockElement->getData(), |
| 499 | + ], |
| 500 | + ), |
| 501 | + ); |
| 502 | + } |
| 503 | + } |
| 504 | + } |
| 505 | + |
| 506 | + return $data; |
| 507 | + } |
| 508 | + |
471 | 509 | /** |
472 | 510 | * @param Model\DataObject\ClassDefinition\Data\Block $mainDefinition |
473 | 511 | */ |
|
0 commit comments