Skip to content

Commit

Permalink
Improve fetching data of repeatable components (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Berdir authored Jul 13, 2023
1 parent 6d3cea9 commit 926669c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/DataTypes/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,24 @@ protected function getSubElements(array $elementData)
if (empty($element)) {
continue;
}
$class = ElementSimpleChoice::class;
if (isset($element['file_id'])) {
$class = null;
if (isset($element['id']) && isset($element['label'])) {
$class = ElementSimpleChoice::class;
} elseif (isset($element['file_id'])) {
$class = ElementSimpleFile::class;
}
if (!is_array($element)) {
} elseif (!is_array($element)) {
$class = ElementSimpleText::class;
$element = ['value' => $element];
}
if (is_array($element) && (isset($element[0]))) {
} elseif (is_array($element)) {
// This is an asset element that allows several files,
// or a mutlichoice element.
$elements[$key] = $this->getSubElements($element);
continue;
}
/** @var \GatherContent\DataTypes\ElementBase[] $elements */
$elements[$key] = new $class($element);
if ($class) {
$elements[$key] = new $class($element);
}
}

return $elements;
Expand Down

0 comments on commit 926669c

Please sign in to comment.