Below is the best way to solve this problem.
First of all, I need to change the Drupal search block and the search form with my field and define a new submit function.
function mymodule_form_search_block_form_alter(&$form, &$form_state, $form_id) { $form['#submit'][] = 'search_form_alter_submit'; $form['site'] = array( '#type' => 'select', '#options' => _options(), '#default_value' => (($_GET['site']) ? $_GET['site'] : '') ); } function mymodule_form_search_form_alter(&$form, &$form_state, $form_id) { $form['#submit'][] = 'search_form_alter_submit'; $form['basic']['site'] = array( '#type' => 'select', '#options' => _options(), '#default_value' => (($_GET['site']) ? $_GET['site'] : '') ); } function _options() { return array( '' => 'Select site', 'site-1' => 'Site 1', 'site-2' => 'Site 2' ); }
The submit function sends us the default search/node page, but with our request. The page will look like search/node/Our-query-string?site=Our-option-selected .
function search_form_alter_submit($form, &$form_state) { $path = $form_state['redirect']; $options = array( 'query' => array( 'site' => $form_state['values']['site'] ) ); drupal_goto($path, $options); }
The next step is to use hook_search_info (do not forget to enable it and set it by default on the admin/config/search/settings page).
function mymodule_search_info() { return array( 'title' => 'Content', 'path' => 'node', 'conditions_callback' => '_conditions_callback', ); }
Condition callback function defined in hook_search_info . We must provide additional requests for our search.
function _conditions_callback($keys) { $conditions = array(); if (!empty($_REQUEST['site'])) { $conditions['site'] = $_REQUEST['site']; } return $conditions; }
Finally, hook_search_execute will filter our content upon our request. I used the default code from this host with the changes I need.
function mymodule_search_execute($keys = NULL, $conditions = NULL) {
I would be glad if someone gives me a better answer.