You are here

function apachesolr_search_custom_page_search_form in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 apachesolr_search.pages.inc \apachesolr_search_custom_page_search_form()
  2. 7 apachesolr_search.pages.inc \apachesolr_search_custom_page_search_form()

Search for placed on user defined search pages.

2 string references to 'apachesolr_search_custom_page_search_form'
apachesolr_search_custom_page in ./apachesolr_search.pages.inc
Returns search results on user defined search pages.
apachesolr_search_search_results in ./apachesolr_search.module
Executes search depending on the conditions given. See apachesolr_search.pages.inc for another use of this function

File

./apachesolr_search.pages.inc, line 44
Provides the page callback for user defined search pages.

Code

function apachesolr_search_custom_page_search_form($form, &$form_state, $search_page, $keys = '') {

  // Loads the core Search CSS file, use the core search module's classes.
  drupal_add_css(drupal_get_path('module', 'search') . '/search.css');
  $form = array();
  $form['#id'] = 'search-form';
  $form['#attributes']['class'][] = 'search-form';
  $form['#search_page'] = $search_page;
  $form['basic'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
  );
  $form['basic']['keys'] = array(
    '#type' => 'textfield',
    '#title' => t('Enter terms'),
    '#default_value' => $keys,
    '#size' => 20,
    '#maxlength' => 255,
  );
  $form['basic']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
  );
  $form['basic']['get'] = array(
    '#type' => 'hidden',
    '#default_value' => json_encode(array_diff_key($_GET, array(
      'q' => 1,
      'page' => 1,
      'solrsort' => 1,
      'retain-filters' => 1,
    ))),
  );
  $fq = NULL;
  if (apachesolr_has_searched($search_page['env_id'])) {
    $query = apachesolr_current_query($search_page['env_id']);

    // We use the presence of filter query params as a flag for the retain filters checkbox.
    $fq = $query
      ->getParam('fq');
  }
  if ($fq || isset($form_state['input']['retain-filters'])) {
    $form['basic']['retain-filters'] = array(
      '#type' => 'checkbox',
      '#title' => t('Retain current filters'),
      '#default_value' => (int) (!empty($_GET['retain-filters'])),
    );
  }
  return $form;
}