From 5ff36934f8c68a5c38fbcfe65c3f80deae37beec Mon Sep 17 00:00:00 2001 From: Denes Gulyas Date: Mon, 15 Feb 2021 12:19:17 +0100 Subject: [PATCH] Add repeatable property to text element to support repeatable settings --- .gitignore | 3 ++- src/DataTypes/ElementTextMeta.php | 6 ++++++ src/DataTypes/Item.php | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e62eb80..afbd3d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ - /bin/ /reports/ /vendor/ + +.phpunit.result.cache diff --git a/src/DataTypes/ElementTextMeta.php b/src/DataTypes/ElementTextMeta.php index 6e14393..8db53d6 100644 --- a/src/DataTypes/ElementTextMeta.php +++ b/src/DataTypes/ElementTextMeta.php @@ -14,6 +14,11 @@ class ElementTextMeta extends Base */ public $validation = []; + /** + * @var array + */ + public $repeatable = []; + /** * {@inheritdoc} */ @@ -30,6 +35,7 @@ protected function initPropertyMapping() [ 'is_plain' => 'isPlain', 'validation' => 'validation', + 'repeatable' => 'repeatable', ] ); diff --git a/src/DataTypes/Item.php b/src/DataTypes/Item.php index 372ea92..53de559 100644 --- a/src/DataTypes/Item.php +++ b/src/DataTypes/Item.php @@ -159,10 +159,17 @@ protected function getSubElements(array $elementData) $elements = []; foreach ($elementData as $element) { + if (empty($element)) { + continue; + } $class = ElementSimpleChoice::class; if (isset($element['file_id'])) { $class = ElementSimpleFile::class; } + if (!is_array($element)) { + $class = ElementSimpleText::class; + $element = ['value' => $element]; + } /** @var \Cheppers\GatherContent\DataTypes\ElementBase[] $elements */ $elements[] = new $class($element); }