Repository navigation
Conversation
When no preference is stored for a user, getPreference now returns false instead of null. This fixes an issue where user preferences would have inverted values displayed in checkboxes. BREAKING CHANGE: Code that relied on the previous default value of null may need adjustment. Users should audit their code that calls getPreference without an explicit default parameter.
Adjust assertions to expect false instead of null when no preference is stored.
|
Thanks for this. I traced the form round trip and the current behavior is correct: the checkbox comes after the hidden input, so PHP keeps the last value. Checked sends "null" (row deleted, default The theme also calls If the goal is an unchecked-by-default consent box, that belongs in the theme: If you're seeing the inverted state on a real install, could you share the steps to reproduce it? A form override or a different serializer could explain it, and I'd like to rule that out. |
Problem
When no preference is stored for a user and a given key,
getPreference()returnednullas the default. This caused an inconsistency with checkbox form inputs:false(unchecked, opt-out by default)trueby default in templates, but returnsnullfrom codeAdditionally, the form field value and the database value were inverted:
falseSolution
Changed the default return value in
getPreference()fromnulltofalse. This ensures consistent behavior where:false(opt-out by default)true=true(explicitly opted-in)false=false(explicitly opted-out)Breaking Change Warning⚠️
This is a breaking change for any code that:
getPreference()without an explicit default parameternullto be returned when no preference is storedRecommendation: Review all code calling
getPreference()and explicitly pass a default value if the previous behavior was intentional. This is especially important for applications with existing user preference data.Related
This fix works in conjunction with the fix to rainlab/vanilla-theme for the promotional emails checkbox.
🤖 Generated with Claude Code