Boolean custom values can't be of type boolean
Overview
The CustomValue APIv4 fails if you pass in a boolean with a value of TRUE
or FALSE
.
Reproduction steps
- Create a multi-record custom field set.
- Create a boolean custom field.
- Try writing to that custom field with a value of
TRUE
orFALSE
. Note that this isn't possible with API Explorer, because that will pass the string"TRUE"
or"FALSE"
.
Current behaviour
Error
value: is not of the right field data type: Boolean
Expected behaviour
Value saves correctly.
Comments
This happens because CRM_Utils_Type::escape()
does a preg_replace
on Boolean fields, assuming they're strings. And on APIv3, that would be correct. On APIv4 we can pass an actual Boolean, which fails because it can't be parsed as a string.
I'm not sure if this belongs more appropriately in CRM_Utils_Type::escape()
or CRM_Utils_Rule::boolean()
. I'll let more knowledgeable folks bikeshed that.