Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Civi/Api4/Service/Autocomplete/CountyAutocompleteProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

namespace Civi\Api4\Service\Autocomplete;

use Civi\Core\Attribute\CiviEventListener;
use Civi\Core\Event\GenericHookEvent;

class CountyAutocompleteProvider {

/**
* Provide default SearchDisplay for County autocompletes
*
* @param \Civi\Core\Event\GenericHookEvent $e
*/
#[CiviEventListener(event: 'civi.search.defaultDisplay')]
public static function on_civi_search_defaultDisplay(GenericHookEvent $e) {
if ($e->display['settings'] || $e->display['type'] !== 'autocomplete' || $e->savedSearch['api_entity'] !== 'County') {
return;
}
$e->display['settings'] = [
'sort' => [
['name', 'ASC'],
],
'columns' => [
[
'type' => 'field',
'key' => 'name',
],
[
'type' => 'field',
'key' => 'name',
'rewrite' => '[name], [state_province_id.abbr]',
],
[
'type' => 'field',
'key' => 'state_province_id.name',
'rewrite' => '[state_province_id.name], [state_province_id.country_id.iso_code]',
],
],
Comment on lines +34 to +49

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!
Might this be helpful too? Or too much?

Suggested change
'columns' => [
[
'type' => 'field',
'key' => 'name',
],
[
'type' => 'field',
'key' => 'state_province_id.name',
],
],
'columns' => [
[
'type' => 'field',
'key' => 'name',
'rewrite' => '[name], [state_province_id.abbr]',
],
[
'type' => 'field',
'key' => 'state_province_id.name',
'rewrite' => '[state_province_id.name], [state_province_id.country_id.iso_code]',
],
],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yeah that's a good idea. I'm not sure it is needed in most cases but when it is needed, it will be useful to have. And it doesn't take up that much room. I did find an Ontario county in New York .... but that's a province in canada not a county.... I'm sure there are some counties in different countries with the same name.

];
}

}