Answers.Body: <p>For customizing the list of options, see <a href="https://civicrm.stackexchange.com/questions/198">this question</a>.</p>
  
  <p>To override the quicksearch behavior, you could try <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_apiWrappers" rel="nofollow noreferrer">hook_civicrm_apiWrappers</a> to modify the output of the contact.getquick api.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-17T14:38:09.783Z
Answers.LastActivityDate: 2015-07-17T14:38:09.783Z
Answers.LastEditDate: 2017-04-13T12:53:13.167Z
Answers.UserDisplayName: Coleman
Answers.Body: <p>I found it quite hard to replace the customization done with hook_civicrm_contactListQuery (CiviCRM &lt;= 4.4) with the new hook_civicrm_apiWrappers (CiviCRM >= 4.5).</p>
  
  <p>So I am sharing my results here.</p>
  
  <p>My goal is to have a way to search quickly either by contact name, or by a custom field that stores a member identifier (different from internal identifier and external identifier).</p>
  
  <p>My old code looked like this :</p>
  
  <pre><code>function myext_civicrm_contactListQuery( &amp;$query, $name, $context, $id ) {
    if ($context == 'navigation') {
      // if not name / email search, just keep the standard behavior
      if (!isset($_GET['tableName']) || $_GET['tableName'] != 'cc') return;
  
      // if the search is a number, try to look for the custom member id
      if (is_numeric($name)) {
        $query = "SELECT cc.id as id, CONCAT_WS( ' :: ', CONCAT(sort_name, ' (', im.num_ro_de_membre_37, ')') ) as data, sort_name
                  FROM civicrm_contact cc
                  LEFT JOIN civicrm_value_r_sum_de_membre_6 im ON ( cc.id = im.entity_id ) 
                  WHERE im.num_ro_de_membre_37 = '$name'
                  AND cc.is_deleted = 0
                  LIMIT 5";
  
      } elseif (strlen($name) &lt; 2) {
        $query = "";
      }
    }
  
  }
  </code></pre>
  
  <p>And now :</p>
  
  <pre><code>function myext_civicrm_apiWrappers(&amp;$wrappers, $apiRequest) {
    if ($apiRequest['entity'] == 'Contact' &amp;&amp; $apiRequest['action'] == 'getquick') {
  
      // search by member id if the search is a numeric value
      if (is_numeric($apiRequest['params']['name'])) {
        $wrappers[] = new CRM_Myext_APIWrapper();
      }   
    }
  }
  
  // i need to do this because there is no function civicrm_api3_contact_getlist
  function emulate_civicrm_api3_contact_getList($params) {
  
    // not loaded by default
    include_once "api/v3/Generic/Getlist.php";
    include_once "api/v3/utils.php";
  
    $apiRequest = array(
      'entity' =&gt; 'Contact',
      'action' =&gt; 'getlist',
      'params' =&gt; $params,
    );  
    $res = civicrm_api3_generic_getList($apiRequest);
  
    // reformat the output to look like getquick
    foreach ($res['values'] as $idx =&gt; $value) {
      $res['values'][$idx]['data'] = $value['extra']['sort_name'] . " ({$value['extra']['custom_37']})";
    }
  
    return $res;
  }
  </code></pre>
  
  <p>And a new APIWrapper class in a dir CRM/Myext/APIWrapper.php :</p>
  
  <pre><code>class CRM_Myext_APIWrapper implements API_Wrapper {
  
    public function fromApiInput($apiRequest) {
  
      // change api call - getquick is deprecated and doesn't work with custom field
      $apiRequest['entity'] = 'Contact';
      $apiRequest['action'] = 'getlist';
      $apiRequest['function'] = 'emulate_civicrm_api3_contact_getList';
  
      // change name param to field custom_37 and remove useless params
      $apiRequest['params']['params']['custom_37'] = $apiRequest['params']['name'];
      unset($apiRequest['params']['name']);
      unset($apiRequest['params']['field_name']);
      unset($apiRequest['params']['table_name']);
  
      // restrict return data (getlist doesn't use return param)
      $apiRequest['params']['extra'] = array('sort_name','custom_37');
  
      return $apiRequest;
    }
  
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-30T14:46:30.647Z
Answers.LastActivityDate: 2017-01-26T19:18:32.843Z
Answers.LastEditDate: 2017-01-26T19:18:32.843Z
Answers.UserDisplayName: samuelsov
Answers.Body: <p>Based on @samuelsov answer and samples I've developed an extension that could customize the quicksearch fields</p>
  
  <p>More info here:
  <a href="https://civicrm.org/extensions/quicksearch" rel="nofollow noreferrer">https://civicrm.org/extensions/quicksearch</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-06T16:16:01.947Z
Answers.Text: The extension is in Core since CiviCRM 5.8.
Answers.UserDisplayName: samuelsov
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-21T11:14:36.883Z
Answers.LastActivityDate: 2018-08-21T11:50:30.807Z
Answers.LastEditDate: 2018-08-21T11:50:30.807Z
Answers.UserDisplayName: luciano_s
Body: <p>I'm trying to customise the top-left quicksearch box so that it recognises some of our internal codes without selecting a specific option in the dropdown. </p>
  
  <p>I used to adapt xavier's great Quick Contact Autocomplete <a href="https://civicrm.org/extensions/quick-contact-autocomplete/version-15" rel="noreferrer">extension</a>, but this uses the crmAutocomplete action which I think went away in 4.5. </p>
  
  <p>Is there a particular recommended way of doing this in 4.5+?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-17T14:30:44.130Z
Comments.Text: What are your internal codes? Custom fields? External identifier core field? Or... ?
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-17T14:34:18.450Z
Comments.Text: External identifier, plus a custom field that's always in a specific format. I taught xavier's extension to recognise the format and fall back to a regular search if not - just trying to replicate that really. Just wanted to save our admin team a couple of clicks on each search.
Comments.UserDisplayName: Andrew West
Tags: <search><quicksearch>
Title: Is there a recommended way to customise the quicksearch?
ThreadText: # Is there a recommended way to customise the quicksearch?
  
  (Asked by: username_0 on 2015-07-17)
  
  I'm trying to customise the top-left quicksearch box so that it recognises some of our internal codes without selecting a specific option in the dropdown.
  
  I used to adapt xavier's great Quick Contact Autocomplete [extension](https://civicrm.org/extensions/quick-contact-autocomplete/version-15), but this uses the crmAutocomplete action which I think went away in 4.5.
  
  Is there a particular recommended way of doing this in 4.5+?
  
  **Tags:** search, quicksearch
  
  > **Comments:**
  > **username_1**: What are your internal codes? Custom fields? External identifier core field? Or... ?  
  > **username_0**: External identifier, plus a custom field that's always in a specific format. I taught xavier's extension to recognise the format and fall back to a regular search if not - just trying to replicate that really. Just wanted to save our admin team a couple of clicks on each search.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2015-07-17. Score: 4 | Accepted answer
  
  For customizing the list of options, see [this question](https://civicrm.stackexchange.com/questions/198).
  
  To override the quicksearch behavior, you could try [hook\_civicrm\_apiWrappers](http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_apiWrappers) to modify the output of the contact.getquick api.
  
  
  ---
  
  ### Answer by username_2 on 2016-05-30. Score: 7
  
  I found it quite hard to replace the customization done with hook\_civicrm\_contactListQuery (CiviCRM <= 4.4) with the new hook\_civicrm\_apiWrappers (CiviCRM >= 4.5).
  
  So I am sharing my results here.
  
  My goal is to have a way to search quickly either by contact name, or by a custom field that stores a member identifier (different from internal identifier and external identifier).
  
  My old code looked like this :
  
  ```
  function myext_civicrm_contactListQuery( &$query, $name, $context, $id ) {
    if ($context == 'navigation') {
      // if not name / email search, just keep the standard behavior
      if (!isset($_GET['tableName']) || $_GET['tableName'] != 'cc') return;
  
      // if the search is a number, try to look for the custom member id
      if (is_numeric($name)) {
        $query = "SELECT cc.id as id, CONCAT_WS( ' :: ', CONCAT(sort_name, ' (', im.num_ro_de_membre_37, ')') ) as data, sort_name
                  FROM civicrm_contact cc
                  LEFT JOIN civicrm_value_r_sum_de_membre_6 im ON ( cc.id = im.entity_id ) 
                  WHERE im.num_ro_de_membre_37 = '$name'
                  AND cc.is_deleted = 0
                  LIMIT 5";
  
      } elseif (strlen($name) < 2) {
        $query = "";
      }
    }
  
  }
  
  ```
  
  And now :
  
  ```
  function myext_civicrm_apiWrappers(&$wrappers, $apiRequest) {
    if ($apiRequest['entity'] == 'Contact' && $apiRequest['action'] == 'getquick') {
  
      // search by member id if the search is a numeric value
      if (is_numeric($apiRequest['params']['name'])) {
        $wrappers[] = new CRM_Myext_APIWrapper();
      }   
    }
  }
  
  // i need to do this because there is no function civicrm_api3_contact_getlist
  function emulate_civicrm_api3_contact_getList($params) {
  
    // not loaded by default
    include_once "api/v3/Generic/Getlist.php";
    include_once "api/v3/utils.php";
  
    $apiRequest = array(
      'entity' => 'Contact',
      'action' => 'getlist',
      'params' => $params,
    );  
    $res = civicrm_api3_generic_getList($apiRequest);
  
    // reformat the output to look like getquick
    foreach ($res['values'] as $idx => $value) {
      $res['values'][$idx]['data'] = $value['extra']['sort_name'] . " ({$value['extra']['custom_37']})";
    }
  
    return $res;
  }
  
  ```
  
  And a new APIWrapper class in a dir CRM/Myext/APIWrapper.php :
  
  ```
  class CRM_Myext_APIWrapper implements API_Wrapper {
  
    public function fromApiInput($apiRequest) {
  
      // change api call - getquick is deprecated and doesn't work with custom field
      $apiRequest['entity'] = 'Contact';
      $apiRequest['action'] = 'getlist';
      $apiRequest['function'] = 'emulate_civicrm_api3_contact_getList';
  
      // change name param to field custom_37 and remove useless params
      $apiRequest['params']['params']['custom_37'] = $apiRequest['params']['name'];
      unset($apiRequest['params']['name']);
      unset($apiRequest['params']['field_name']);
      unset($apiRequest['params']['table_name']);
  
      // restrict return data (getlist doesn't use return param)
      $apiRequest['params']['extra'] = array('sort_name','custom_37');
  
      return $apiRequest;
    }
  
  }
  
  ```
  
  
  ---
  
  ### Answer by username_3 on 2018-08-21. Score: 2
  
  Based on @username_2 answer and samples I've developed an extension that could customize the quicksearch fields
  
  More info here:
  <https://civicrm.org/extensions/quicksearch>
  
  > **Comments:**
  > **username_2**: The extension is in Core since CiviCRM 5.8.  
  
  ---
  
  