Skip to content

Commit 51f139c

Browse files
committed
Add default values in eval key
1 parent 1005646 commit 51f139c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Contao/Widgets/MultiColumnWizard.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ class MultiColumnWizard extends Widget
170170

171171
private ?TranslatorInterface $translator = null;
172172

173+
/**
174+
* @var array|mixed|string|string[]|null
175+
*/
176+
private mixed $defaultValue;
177+
173178
/**
174179
* Initialize the object
175180
*
@@ -257,6 +262,10 @@ public function __set($strKey, $varValue)
257262
}
258263
break;
259264

265+
case 'default':
266+
$this->defaultValue = StringUtil::deserialize($varValue, true);
267+
break;
268+
260269
case 'mandatory':
261270
$this->arrConfiguration['mandatory'] = $varValue ? true : false;
262271
break;
@@ -804,6 +813,10 @@ public function generate($overwriteRowCurrentRow = null, $onlyRows = false)
804813
}
805814

806815
$intNumberOfRows = max(count($this->varValue), 1);
816+
$useDefaultValue = (0 == count($this->varValue));
817+
if($useDefaultValue && !empty($this->defaultValue)) {
818+
$intNumberOfRows = count($this->defaultValue);
819+
}
807820

808821
// always show the minimum number of rows if set
809822
if ($this->minCount && ($intNumberOfRows < $this->minCount)) {
@@ -839,6 +852,11 @@ public function generate($overwriteRowCurrentRow = null, $onlyRows = false)
839852
$arrField = array_merge($arrField, $this->arrRowSpecificData[$i][$strKey]);
840853
}
841854

855+
// Should we do this above the foreach and run a foreach twice ... nope.
856+
if ($useDefaultValue && !empty($this->defaultValue[$i][$strKey] ?? null)) {
857+
$this->varValue[$i][$strKey] = $this->defaultValue[$i][$strKey];
858+
}
859+
842860
$objWidget = $this->initializeWidget(
843861
$arrField,
844862
$i,

0 commit comments

Comments
 (0)