Cannot set Entityref fields via APIv4 Explorer - on multi-value data
Overview
Adding EntityRef data in APIv4 explorer fails on multi-value data, because validation in CRM_Utils_Type doesn't support EntityRef.
Reproduction steps
- Create a multi-value data set for all Individuals
- Add an EntityRef field linked to Activities
- Try to set it via the APIv4 Explorer
As of this second this is failing on the WP Demo site: https://wpmaster.demo.civicrm.org/wp-admin/admin.php?page=CiviCRM&q=civicrm%2Fapi4#/explorer/Custom_Test_Multi/create?values=%5B%5B%22entity_id%22,%2256%22%5D,%5B%22Test_EntityRef_on_Multi%22,%22459%22%5D%5D
Current behaviour
There's one error in CRM_Utils_Type::escape() and two in CRM_Utils_Type::validate()
CRM_Utils_Type::escape
Just needs EntityReference added to the switch statement (I think)
CRM_Utils_Type::validate
Needs EntityReference added to $possibleTypes (I think)
Needs a case added for EntityReference. This works as a temporary workaround:
case 'EntityReference':
// null is valid
if (strlen(trim($data)) == 0) {
return trim($data);
}
return (int) $data;
But presumably it needs some kind of validation like happens in ContactReference:
case 'ContactReference':
// null is valid
if (strlen(trim($data)) == 0) {
return trim($data);
}
if (CRM_Utils_Rule::validContact($data)) {
return (int) $data;
}
break;
Environment information
Replicated on 5.60 and 5.62alpha1