diff --git a/src/Import.php b/src/Import.php index a579e6f..8f925fd 100644 --- a/src/Import.php +++ b/src/Import.php @@ -213,6 +213,13 @@ private function importRecord(ContentType $contentType, Collection $record): voi if (is_array(current(array_values($fieldData)))) { // We are importing a block foreach ($fieldData as $setName => $setValue) { + // Turn `['value' => 123, '_id' => 'pages/mission']` into the correct Content ID + if (is_iterable($value) && + array_key_exists(0, $value) && + (array_key_exists('_id', $value[0]) || array_key_exists('reference', $value[0]))) { + $value = $this->getMultipleValues($value); + } + $this->data['collections'][$key][$setName][$i] = $setValue; $this->data['collections'][$key]['order'][] = $i; $i++; @@ -225,6 +232,13 @@ private function importRecord(ContentType $contentType, Collection $record): voi $i++; foreach ($fieldData as $name => $value) { + // Turn `['value' => 123, '_id' => 'pages/mission']` into the correct Content ID + if (is_iterable($value) && + array_key_exists(0, $value) && + (array_key_exists('_id', $value[0]) || array_key_exists('reference', $value[0]))) { + $value = $this->getMultipleValues($value); + } + $this->data['collections'][$key][$setName][$i][$name] = $value; $this->data['collections'][$key]['order'][] = $i; } @@ -325,7 +339,7 @@ private function importRecord(ContentType $contentType, Collection $record): voi $fieldDefinition = $content->getDefinition()->get('fields')[$key]; // Handle collections if ($fieldDefinition['type'] === 'collection') { - $data = $this->preFillCollection($fieldDefinition, $key, $item); + $data = $this->preFillCollection($key, $item); $this->contentEditController->updateCollections($content, $data, null); } else { @@ -423,7 +437,7 @@ private function isLocalisedField(Content $content, string $key, $item): bool return true; } - private function preFillCollection($fieldDefinition, $key, $collectionArray): array + private function preFillCollection($key, $collectionArray): array { $data = [ 'collections' => [ @@ -450,6 +464,7 @@ private function nestedSelectResolver($fieldData): array if ($fieldData['type'] === 'set') { foreach ($fieldData['value'] as $key => $value) { + // Turn `['id' => 123, 'reference' => 'pages/mission']` into the correct Content ID if (is_iterable($value) && array_key_exists(0, $value) && (array_key_exists('_id', $value[0]) || array_key_exists('reference', $value[0]))) {