Skip to content

Commit

Permalink
Update Import.php
Browse files Browse the repository at this point in the history
  • Loading branch information
bobdenotter authored Mar 23, 2022
1 parent b3562ab commit 8a2aee8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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' => [
Expand All @@ -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]))) {
Expand Down

0 comments on commit 8a2aee8

Please sign in to comment.