Skip to content

Commit

Permalink
Do not use Arrays::walk as it messes up keys
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk authored Jan 29, 2024
1 parent 49ce753 commit 0224dbb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/Controls/CheckboxListEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ public function getCases(): array
*/
public function setItems(array $enums, bool $useKeys = true): self
{
$items = Arrays::walk($enums, function(LabeledEnum $enum) {
$items = [];

foreach ($enums as $enum) {
if (!$enum instanceof $this->enumType) {
throw new InvalidArgumentException('Enum does not match items of type '.$this->enumType);
}

yield $enum->value => $enum->label();
});
$items[$enum->value] = $enum->label();
}

return parent::setItems($items, $useKeys);
}
Expand Down
8 changes: 5 additions & 3 deletions src/Controls/RadioListEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ public function getCases(): array
*/
public function setItems(array $enums, bool $useKeys = true): self
{
$items = Arrays::walk($enums, function(LabeledEnum $enum) {
$items = [];

foreach ($enums as $enum) {
if (!$enum instanceof $this->enumType) {
throw new InvalidArgumentException('Enum does not match items of type '.$this->enumType);
}

yield $enum->value => $enum->label();
});
$items[$enum->value] = $enum->label();
}

return parent::setItems($items, $useKeys);
}
Expand Down
8 changes: 5 additions & 3 deletions src/Controls/SelectBoxEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ public function setEnumType(string $enumType): self
*/
public function setItems(array $enums, bool $useKeys = true, bool $badge = false): self
{
$items = Arrays::walk($enums, function(LabeledEnum $enum) use ($badge) {
$items = [];

foreach ($enums as $enum) {
if (!$enum instanceof $this->enumType) {
throw new InvalidArgumentException('Enum does not match items of type '.$this->enumType);
}

yield $enum->value => Html::optionEnum($enum, $badge);
});
$items[$enum->value] = Html::optionEnum($enum, $badge);
}

return parent::setItems($items, $useKeys);
}
Expand Down

0 comments on commit 0224dbb

Please sign in to comment.