silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
720 stars 820 forks source link

Better casting in `ViewableData` #11262

Open GuySartorelli opened 1 month ago

GuySartorelli commented 1 month ago

Right now the $casting configuration on ViewableData only kicks in if the value that should be cast is not already an object. This means if a method returns some instance of DBField the casting configuration will be ignored.

The casting also doesn't care what the original value is - so the default cast of Text will cast e.g. booleans to DBText instead of to DBBoolean

More recently this caused problems when trying to allow push associative arrays to templates in https://github.com/silverstripe/silverstripe-framework/issues/11237. We wanted to treat associative arrays as ArrayData, but this resulted in bypassing casting, which caused problems in various areas of kitchen sink.

Notes

Acceptance Criteria