*
* @param array $params
* Associative array of property name-value pairs to insert in new saved search.
- * @example SavedSearch/Create.php Std create example.
+ *
* @return array
* api result array
* {@getfields saved_search_create}
+ *
+ * @throws \API_Exception
+ *
+ * @example SavedSearch/Create.php Std create example.
* @access public
*/
function civicrm_api3_saved_search_create($params) {
- civicrm_api3_verify_one_mandatory($params, NULL, ['form_values', 'where_clause']);
-
$result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'SavedSearch');
_civicrm_api3_saved_search_result_cleanup($result);
return $result;
*/
function _civicrm_api3_saved_search_create_spec(&$fields) {
$fields['form_values']['api.aliases'][] = 'formValues';
+ $fields['form_values']['api.required'] = TRUE;
}
/**
* @param array $params
* Associative array of property name-value pairs. $params['id'] should be
* the ID of the saved search to be deleted.
- * @example SavedSearch/Delete.php Std delete example.
+ *
* @return array
* api result array
* {@getfields saved_search_delete}
+ *
+ * @throws \API_Exception
+ * @throws \CiviCRM_API3_Exception
+ *
+ * @example SavedSearch/Delete.php Std delete example.
* @access public
*/
function civicrm_api3_saved_search_delete($params) {
}
/**
- * This function unserializes the form_values in an SavedSearch API result.
+ * Unserialize the form_values field in SavedSearch API results.
+ *
+ * Note: APIv4 handles serialization automatically based on metadata.
*
* @param array $result API result to be cleaned up.
*/
function _civicrm_api3_saved_search_result_cleanup(&$result) {
if (isset($result['values']) && is_array($result['values'])) {
- // Only clean up the values if there are values. (A getCount operation
- // for example does not return values.)
+ // Only run if there are values (getCount for example does not return values).
foreach ($result['values'] as $key => $value) {
- $result['values'][$key]['form_values'] = \CRM_Utils_String::unserialize($value['form_values']);
+ if (isset($value['form_values'])) {
+ $result['values'][$key]['form_values'] = CRM_Utils_String::unserialize($value['form_values']);
+ }
}
}
}