yii2
yii2 copied to clipboard
BaseHtml fix renderSelectOptions for Enum
| Q | A |
|---|---|
| Is bugfix? | ✔️ |
| New feature? | ❌ |
| Breaks BC? | ❌ |
| Fixed issues BaseHtml fix renderSelectOptions for Enum |
PR Summary
- Update to selection conditions in 'BaseHtml.php' The logic for deciding what gets 'selected' in the 'renderSelectOptions' function has been improved. Now, it also checks if the 'selection' is an object, and if that's the case, it makes a comparison based on the 'value' attribute instead. This results in a more versatile and accurate selection process.
Codecov Report
Patch coverage: 100.00% and project coverage change: -1.29% :warning:
Comparison is base (
73902f0) 48.90% compared to head (bb7af07) 47.61%.
Additional details and impacted files
@@ Coverage Diff @@
## master #19928 +/- ##
==========================================
- Coverage 48.90% 47.61% -1.29%
==========================================
Files 445 445
Lines 42806 42806
==========================================
- Hits 20935 20383 -552
- Misses 21871 22423 +552
| Files Changed | Coverage Δ | |
|---|---|---|
| framework/helpers/BaseHtml.php | 99.33% <100.00%> (ø) |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
I also think that using instanceof UnitEnum would be better - it should be safer than changing behavior for all objects.
And IMO it should be done at the beginning of $selection processing:
if ($selection !== null) {
if ($selection instanceof \UnitEnum) {
$selection = $selection->value;
}
...
I also think that using
instanceof UnitEnumwould be better - it should be safer than changing behavior for all objects.And IMO it should be done at the beginning of
$selectionprocessing:if ($selection !== null) { if ($selection instanceof \UnitEnum) { $selection = $selection->value; } ...
Well i tried your fix but its not working because we are using this: https://github.com/spatie/enum
Its not really an Enum, actually its a Class extending an Enum class which doesnt implement UnitEnum...
abstract class Enum extends \Spatie\Enum\Enum
abstract class Enum implements JsonSerializable
I don't think we should support any object here, this should be out of the scope of the framework and it should depend on the developers to extend framework functionality in their own app to support any custom solution like in your case. Still, we would accept real enums here.
are you submitting fixes for some of your internal code to the public? Why are you not checking the type of value property then?
Another useless PR. @samdark I hope we're not thinking of adapting this
Is this PR ready?
Hey, this issue can be closed, we took a different approach so Is no longer needed. It was a bug on the framework regarding support for enums. If I remember correctly if we used an enum object the render option wasn't working.
I'm closing it then. Still, PR introducing support for enums is welcome.