- Added enums to select values
This commit is contained in:
parent
363da77669
commit
9ddb93b847
@ -79,13 +79,23 @@ class UiSelect extends UiElement implements Extension {
|
||||
return $option;
|
||||
}
|
||||
|
||||
protected function isSelected($check, $value, bool $strict = true) : bool
|
||||
protected function isSelected($check, mixed $value, bool $strict = true) : bool
|
||||
{
|
||||
if ( is_array($value) ) {
|
||||
return in_array($check, $value, $strict);
|
||||
return in_array($check, array_map(fn($e) => $this->normalizeValue($e), $value), $strict);
|
||||
}
|
||||
|
||||
$value = $this->normalizeValue($value);
|
||||
|
||||
return $strict ? $check === $value : $check == $value;
|
||||
}
|
||||
|
||||
protected function normalizeValue(mixed $value) : mixed
|
||||
{
|
||||
if ($value instanceof \BackedEnum) {
|
||||
return $value->value;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ class FormContext implements FormContextInterface
|
||||
is_null($value) => null,
|
||||
enum_exists($e) => ( $value instanceof \BackedEnum ? $value : $e::tryFrom($value) ) ?? throw new \InvalidArgumentException(sprintf("Field '\$$property' awaiting values : '%s'.", implode("', '", array_map(fn($e) => $e->value, $e::cases())))),
|
||||
function_exists($e) => $e($value),
|
||||
class_exists($e) => new $e($value),
|
||||
class_exists($e) => new $e(...$value),
|
||||
interface_exists($e) => throw new \InvalidArgumentException("There is no way provided to match an interface object yet."),
|
||||
default => $value
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user