if (in_array($id, $legacyElements) && is_array($values)) {
// prior to 4.7, formValues for some attributes (e.g. group, tag) are stored in array(id1 => 1, id2 => 1),
// as per the recent Search fixes $values need to be in standard array(id1, id2) format
- $ids = array_keys($values, 1);
- if (count($ids) > 1 ||
- (count($ids) == 1 &&
- (key($values) > 1 ||
- is_string(key($values)) ||
- (key($values) == 1 && $values[1] == 1) // handle (0 => 4), (1 => 1)
- )
- )
- ) {
- $values = $ids;
- }
+ CRM_Utils_Array::formatArrayKeys($values);
}
}
return $result;
}
+ /**
+ * Convert array where key(s) holds the actual value and value(s) as 1 into array of actual values
+ * Ex: array('foobar' => 1, 4 => 1) formatted into array('foobar', 4)
+ *
+ * @param array $array
+ * @return void
+ */
+ public static function formatArrayKeys(&$array) {
+ $keys = array_keys($array, 1);
+ if (count($keys) > 1 ||
+ (count($keys) == 1 &&
+ (key($array) > 1 ||
+ is_string(key($array)) ||
+ (key($array) == 1 && $array[1] == 1) // handle (0 => 4), (1 => 1)
+ )
+ )
+ ) {
+ $array = $keys;
+ }
+ }
+
}