From 3b775224708ee4cc36308422c7e47d506d27d7bd Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 16 Feb 2023 18:12:58 -0500 Subject: [PATCH] Add APIv4 Pledge Autocomplete Fixes dev/core#4131 --- .../PledgeAutocompleteProvider.php | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Civi/Api4/Service/Autocomplete/PledgeAutocompleteProvider.php diff --git a/Civi/Api4/Service/Autocomplete/PledgeAutocompleteProvider.php b/Civi/Api4/Service/Autocomplete/PledgeAutocompleteProvider.php new file mode 100644 index 000000000000..7e7e22964b14 --- /dev/null +++ b/Civi/Api4/Service/Autocomplete/PledgeAutocompleteProvider.php @@ -0,0 +1,86 @@ +savedSearch) || $e->savedSearch['api_entity'] !== 'Pledge') { + return; + } + $e->savedSearch['api_params'] = [ + 'version' => 4, + 'select' => [ + 'id', + 'contact_id.display_name', + 'amount', + 'start_date', + 'end_date', + 'financial_type_id:label', + ], + 'orderBy' => [], + 'where' => [], + 'groupBy' => [], + 'join' => [], + 'having' => [], + ]; + } + + /** + * Provide default SearchDisplay for Pledge autocompletes + * + * @param \Civi\Core\Event\GenericHookEvent $e + */ + public static function on_civi_search_defaultDisplay(GenericHookEvent $e) { + if ($e->display['settings'] || $e->display['type'] !== 'autocomplete' || $e->savedSearch['api_entity'] !== 'Pledge') { + return; + } + $e->display['settings'] = [ + 'sort' => [ + ['contact_id.sort_name', 'ASC'], + ['amount', 'ASC'], + ['start_date', 'DESC'], + ], + 'columns' => [ + [ + 'type' => 'field', + 'key' => 'contact_id.display_name', + 'rewrite' => '[contact_id.display_name] - [amount]', + ], + [ + 'type' => 'field', + 'key' => 'financial_type_id:label', + 'rewrite' => '#[id] [financial_type_id:label]', + ], + [ + 'type' => 'field', + 'key' => 'start_date', + 'rewrite' => '[start_date] - [end_date]', + ], + ], + ]; + } + +}