You are here

function apachesolr_autocomplete_form_alter in Apache Solr Autocomplete 7

Same name and namespace in other branches
  1. 7.2 apachesolr_autocomplete.module \apachesolr_autocomplete_form_alter()

Implementation of hook_form_alter().

File

./apachesolr_autocomplete.module, line 36
Alters search forms to suggest terms using Apache Solr using AJAX. Thanks to: robertDouglass who contributed some of the code. sch4lly for contributing to D7 version

Code

function apachesolr_autocomplete_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'search_form':
      if ($form['module']['#value'] == 'apachesolr_search' || $form['module']['#value'] == 'apachesolr_multisitesearch') {
        $element =& $form['basic']['keys'];
        $context_id = 'apachesolr_search_page:' . apachesolr_search_default_search_page();
      }
      break;
    case 'search_block_form':
      $element =& $form['search_block_form'];
      $context_id = 'apachesolr_search_page:' . apachesolr_search_default_search_page();
      break;
    case 'apachesolr_search_custom_page_search_form':
      $element =& $form['basic']['keys'];
      $context_id = 'apachesolr_search_page:' . $form['#search_page']['page_id'];
      break;
  }

  // Do the actual form altering.
  if (isset($context_id) && isset($element)) {
    apachesolr_autocomplete_do_alter($element, $form, $context_id);
  }
}