mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #10470 from creative-commoners/pulls/4.11/case-insensitive-casting
FIX Normalise casing before casting fields
This commit is contained in:
commit
7e9ced0824
@ -319,9 +319,12 @@ class ViewableData implements IteratorAggregate
|
||||
*/
|
||||
public function castingHelper($field)
|
||||
{
|
||||
$specs = static::config()->get('casting');
|
||||
if (isset($specs[$field])) {
|
||||
return $specs[$field];
|
||||
// Get casting if it has been configured.
|
||||
// DB fields and PHP methods are all case insensitive so we normalise casing before checking.
|
||||
$specs = array_change_key_case(static::config()->get('casting'), CASE_LOWER);
|
||||
$fieldLower = strtolower($field);
|
||||
if (isset($specs[$fieldLower])) {
|
||||
return $specs[$fieldLower];
|
||||
}
|
||||
|
||||
// If no specific cast is declared, fall back to failover.
|
||||
|
Loading…
Reference in New Issue
Block a user