Search Builder: Fails validation when state_province location type is "primary" and operator is "IN"
Steps to Replicate
- On Search Builder, select Contacts, State, Primary, In, and at least one value.
- Press Search.
Expected Result
Search completes.
Actual result
This field fails validation with the error Please Enter a Value.
This is down to PR #8890/CRM-19081, which introduced special handling for the state_province
field in Search Builder to handle legacy smart groups.
That PR added this:
if (!is_numeric($value) && $fldName == 'state_province') {
$value = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Address', 'state_province_id', $value);
}
The ticket isn't specific, but this code suggests that legacy smart groups passed a state name
or abbreviation
rather than an ID.
The issue arises with the IN
operator because it's not passing a numeric value but an array Passing an array to getKey
returns NULL
, causing the bug. Adding an is_array
check to that if
solves the problem.
I see that PR #8890 has a test, so I'm going to take a quick crack at writing a Search Builder test before submitting my patch.