From eca2f18b0230613baf9778b2e1f39e1e233ad650 Mon Sep 17 00:00:00 2001 From: colemanw Date: Thu, 29 Jun 2023 14:10:01 -0400 Subject: [PATCH] CiviGrant - Support APIv4 autocompletes --- .../GrantAutocompleteProvider.php | 83 +++++++++++++++++++ ext/civigrant/info.xml | 1 + 2 files changed, 84 insertions(+) create mode 100644 ext/civigrant/Civi/Api4/Service/Autocomplete/GrantAutocompleteProvider.php diff --git a/ext/civigrant/Civi/Api4/Service/Autocomplete/GrantAutocompleteProvider.php b/ext/civigrant/Civi/Api4/Service/Autocomplete/GrantAutocompleteProvider.php new file mode 100644 index 0000000000..e5c0388126 --- /dev/null +++ b/ext/civigrant/Civi/Api4/Service/Autocomplete/GrantAutocompleteProvider.php @@ -0,0 +1,83 @@ +savedSearch) || $e->savedSearch['api_entity'] !== 'Grant') { + return; + } + $e->savedSearch['api_params'] = [ + 'version' => 4, + 'select' => [ + 'id', + 'contact_id.display_name', + 'grant_type_id:label', + 'financial_type_id:label', + 'status_id:label', + ], + 'orderBy' => [], + 'where' => [], + 'groupBy' => [], + 'join' => [], + 'having' => [], + ]; + } + + /** + * Provide default SearchDisplay for Grant 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'] !== 'Grant') { + return; + } + $e->display['settings'] = [ + 'sort' => [ + ['contact_id.sort_name', 'ASC'], + ['application_received_date', 'DESC'], + ], + 'columns' => [ + [ + 'type' => 'field', + 'key' => 'contact_id.display_name', + 'rewrite' => '[contact_id.display_name] - [grant_type_id:label]', + ], + [ + 'type' => 'field', + 'key' => 'financial_type_id:label', + 'rewrite' => '#[id] [status_id:label]', + ], + [ + 'type' => 'field', + 'key' => 'financial_type_id:label', + ], + ], + ]; + } + +} diff --git a/ext/civigrant/info.xml b/ext/civigrant/info.xml index 3a4b1fadc3..6fbacfc600 100644 --- a/ext/civigrant/info.xml +++ b/ext/civigrant/info.xml @@ -34,6 +34,7 @@ afform-entity-php@1.0.0 smarty-v2@1.0.1 entity-types-php@1.0.0 + scan-classes@1.0.0 CRM/Grant -- 2.25.1