From 5773bd73f220661408517d5863202d927b6ee488 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 31 Jan 2023 21:48:16 -0500 Subject: [PATCH] Fix dev/core#4104 - APIv4 autocomplete for contributions --- .../ContributionAutocompleteProvider.php | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 Civi/Api4/Service/Autocomplete/ContributionAutocompleteProvider.php diff --git a/Civi/Api4/Service/Autocomplete/ContributionAutocompleteProvider.php b/Civi/Api4/Service/Autocomplete/ContributionAutocompleteProvider.php new file mode 100644 index 0000000000..0e05a824d4 --- /dev/null +++ b/Civi/Api4/Service/Autocomplete/ContributionAutocompleteProvider.php @@ -0,0 +1,84 @@ +savedSearch) || $e->savedSearch['api_entity'] !== 'Contribution') { + return; + } + $e->savedSearch['api_params'] = [ + 'version' => 4, + 'select' => [ + 'id', + 'contact_id.display_name', + 'total_amount', + 'receive_date', + 'financial_type_id:label', + ], + 'orderBy' => [], + 'where' => [], + 'groupBy' => [], + 'join' => [], + 'having' => [], + ]; + } + + /** + * Provide default SearchDisplay for Contribution 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'] !== 'Contribution') { + return; + } + $e->display['settings'] = [ + 'sort' => [ + ['contact_id.sort_name', 'ASC'], + ['total_amount', 'ASC'], + ['receive_date', 'DESC'], + ], + 'columns' => [ + [ + 'type' => 'field', + 'key' => 'contact_id.display_name', + 'rewrite' => '[contact_id.display_name] - [total_amount]', + ], + [ + 'type' => 'field', + 'key' => 'financial_type_id:label', + 'rewrite' => '#[id] [financial_type_id:label]', + ], + [ + 'type' => 'field', + 'key' => 'receive_date', + ], + ], + ]; + } + +} -- 2.25.1