Skip to content

Commit 5e4dcb7

Browse files
fix: block fields should rewrite references
Error: when using "Paste recursive, updating references" relation fields within blocks were not updated Caused by: ClassDefinition\Data\Block not implementing IdRewriterInterface Resolved with: implement IdRewriterInterface and rewriteIds method
1 parent 06fedfd commit 5e4dcb7

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

  • models/DataObject/ClassDefinition/Data

models/DataObject/ClassDefinition/Data/Block.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
use Pimcore\Normalizer\NormalizerInterface;
3131
use Pimcore\Tool\Serialize;
3232

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
3434
{
3535
use DataObject\Traits\ClassSavedTrait;
3636
use DataObject\Traits\FieldDefinitionEnrichmentDataTrait;
@@ -468,6 +468,44 @@ public function getDiffVersionPreview(?array $data, ?Concrete $object = null, ar
468468
return $value;
469469
}
470470

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+
471509
/**
472510
* @param Model\DataObject\ClassDefinition\Data\Block $mainDefinition
473511
*/

0 commit comments

Comments
 (0)