From e83339a05a7f64305e4b8fbaca547f400f2bb829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Alejandro=20L=C3=B3pez=20L=C3=B3pez?= Date: Mon, 27 Jan 2025 15:28:50 -0500 Subject: [PATCH 1/2] Add support for enums on Html methods --- framework/helpers/BaseHtml.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/framework/helpers/BaseHtml.php b/framework/helpers/BaseHtml.php index ff81df22752..bdb7b189ca9 100644 --- a/framework/helpers/BaseHtml.php +++ b/framework/helpers/BaseHtml.php @@ -2311,6 +2311,12 @@ public static function getAttributeValue($model, $attribute) $value = $value->getPrimaryKey(false); return is_array($value) ? json_encode($value) : $value; + } elseif (version_compare(PHP_VERSION, '8.1.0') >= 0) { + if ($value instanceof \BackedEnum) { + $value = $value->value; + } elseif ($value instanceof \UnitEnum) { + $value = $value->name; + } } return $value; From 17d7e687a2ff3dd2f1cea3d30b7d2ecb3d790b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Alejandro=20L=C3=B3pez=20L=C3=B3pez?= Date: Mon, 27 Jan 2025 15:30:18 -0500 Subject: [PATCH 2/2] Add support for enum on RangeValidator's client validation --- framework/validators/RangeValidator.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/framework/validators/RangeValidator.php b/framework/validators/RangeValidator.php index e58ea601096..8c3a7184f51 100644 --- a/framework/validators/RangeValidator.php +++ b/framework/validators/RangeValidator.php @@ -124,6 +124,13 @@ public function getClientOptions($model, $attribute) { $range = []; foreach ($this->range as $value) { + if (version_compare(PHP_VERSION, '8.1.0') >= 0) { + if ($value instanceof \BackedEnum) { + $value = $value->value; + } elseif ($value instanceof \UnitEnum) { + $value = $value->name; + } + } $range[] = (string) $value; } $options = [