Skip to content

Commit

Permalink
Add default values in eval key
Browse files Browse the repository at this point in the history
  • Loading branch information
zonky2 committed Dec 28, 2024
1 parent 1005646 commit 51f139c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Contao/Widgets/MultiColumnWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ class MultiColumnWizard extends Widget

private ?TranslatorInterface $translator = null;

/**
* @var array|mixed|string|string[]|null
*/
private mixed $defaultValue;

/**
* Initialize the object
*
Expand Down Expand Up @@ -257,6 +262,10 @@ public function __set($strKey, $varValue)
}
break;

case 'default':
$this->defaultValue = StringUtil::deserialize($varValue, true);
break;

case 'mandatory':
$this->arrConfiguration['mandatory'] = $varValue ? true : false;
break;
Expand Down Expand Up @@ -804,6 +813,10 @@ public function generate($overwriteRowCurrentRow = null, $onlyRows = false)
}

$intNumberOfRows = max(count($this->varValue), 1);
$useDefaultValue = (0 == count($this->varValue));
if($useDefaultValue && !empty($this->defaultValue)) {

Check failure on line 817 in src/Contao/Widgets/MultiColumnWizard.php

View workflow job for this annotation

GitHub Actions / build (~4.13.0, 8.1, update)

Expected 1 space after IF keyword; 0 found (reported by phpcs: Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword)

Check failure on line 817 in src/Contao/Widgets/MultiColumnWizard.php

View workflow job for this annotation

GitHub Actions / build (~4.13.0, 8.2, update, --exit-0)

Expected 1 space after IF keyword; 0 found (reported by phpcs: Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword)

Check failure on line 817 in src/Contao/Widgets/MultiColumnWizard.php

View workflow job for this annotation

GitHub Actions / build (~5.3.0, 8.1, update)

Expected 1 space after IF keyword; 0 found (reported by phpcs: Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword)

Check failure on line 817 in src/Contao/Widgets/MultiColumnWizard.php

View workflow job for this annotation

GitHub Actions / build (~5.3.0, 8.2, update)

Expected 1 space after IF keyword; 0 found (reported by phpcs: Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword)

Check failure on line 817 in src/Contao/Widgets/MultiColumnWizard.php

View workflow job for this annotation

GitHub Actions / build (~5.3.0, 8.3, update, --exit-0)

Expected 1 space after IF keyword; 0 found (reported by phpcs: Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword)

Check failure on line 817 in src/Contao/Widgets/MultiColumnWizard.php

View workflow job for this annotation

GitHub Actions / build (~4.13.0, 8.1, update)

Expected 1 space after IF keyword; 0 found (reported by phpcs: Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword)

Check failure on line 817 in src/Contao/Widgets/MultiColumnWizard.php

View workflow job for this annotation

GitHub Actions / build (~4.13.0, 8.2, update, --exit-0)

Expected 1 space after IF keyword; 0 found (reported by phpcs: Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword)

Check failure on line 817 in src/Contao/Widgets/MultiColumnWizard.php

View workflow job for this annotation

GitHub Actions / build (~5.3.0, 8.1, update)

Expected 1 space after IF keyword; 0 found (reported by phpcs: Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword)

Check failure on line 817 in src/Contao/Widgets/MultiColumnWizard.php

View workflow job for this annotation

GitHub Actions / build (~5.3.0, 8.2, update)

Expected 1 space after IF keyword; 0 found (reported by phpcs: Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword)

Check failure on line 817 in src/Contao/Widgets/MultiColumnWizard.php

View workflow job for this annotation

GitHub Actions / build (~5.3.0, 8.3, update, --exit-0)

Expected 1 space after IF keyword; 0 found (reported by phpcs: Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword)
$intNumberOfRows = count($this->defaultValue);
}

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

// Should we do this above the foreach and run a foreach twice ... nope.
if ($useDefaultValue && !empty($this->defaultValue[$i][$strKey] ?? null)) {
$this->varValue[$i][$strKey] = $this->defaultValue[$i][$strKey];
}

$objWidget = $this->initializeWidget(
$arrField,
$i,
Expand Down

0 comments on commit 51f139c

Please sign in to comment.