function apachesolr_search_form_alter in Apache Solr Search 5.2
Implementation of hook_form_alter().
This adds options to the apachesolr admin form.
File
- ./
apachesolr_search.module, line 853 - Provides a content search implementation for node content for use with the Apache Solr search application.
Code
function apachesolr_search_form_alter($form_id, &$form) {
switch ($form_id) {
case 'apachesolr_delete_index_form':
if ($form_values['op'] == t('Delete the index')) {
// In D6: $form['submit']['#submit'][] = 'apaechesolr_search_build_spellcheck';
$form['#submit']['apachesolr_search_build_spellcheck'] = array();
}
break;
case 'search_form':
if ($form['module']['#value'] == 'apachesolr_search') {
$form['#submit']['apachesolr_search_form_search_submit'] = array();
// No other modification make sense unless a query is active.
// Note - this means that the query must always be run before
// calling drupal_get_form('search_form').
$apachesolr_has_searched = apachesolr_has_searched();
$queryvalues = array();
if ($apachesolr_has_searched) {
$query = apachesolr_current_query();
$queryvalues = $query
->get_url_queryvalues();
}
$form['basic']['apachesolr_search']['#tree'] = TRUE;
$form['basic']['apachesolr_search']['queryvalues'] = array(
'#type' => 'hidden',
'#default_value' => serialize($queryvalues),
);
$form['basic']['apachesolr_search']['get'] = array(
'#type' => 'hidden',
'#default_value' => serialize(array_diff_key($_GET, array(
'q' => 1,
'page' => 1,
'filters' => 1,
'solrsort' => 1,
'retain-filters' => 1,
))),
);
if ($queryvalues || isset($_POST['apachesolr_search']['retain-filters'])) {
$form['basic']['apachesolr_search']['retain-filters'] = array(
'#type' => 'checkbox',
'#title' => t('Retain current filters'),
'#default_value' => (int) isset($_GET['retain-filters']),
);
}
if (variable_get('apachesolr_search_spellcheck', FALSE) && $apachesolr_has_searched && ($response = apachesolr_static_response_cache())) {
//Get spellchecker suggestions into an array.
if (isset($response->spellcheck->suggestions) && $response->spellcheck->suggestions) {
$suggestions = get_object_vars($response->spellcheck->suggestions);
if ($suggestions) {
//Get the original query and replace words.
$query = apachesolr_current_query();
foreach ($suggestions as $word => $value) {
$replacements[$word] = $value->suggestion[0];
}
$new_keywords = strtr($query
->get_query_basic(), $replacements);
// Show only if suggestion is different than current query.
if ($query
->get_query_basic() != $new_keywords) {
$form['basic']['suggestion'] = array(
'#prefix' => '<div class="spelling-suggestions">',
'#suffix' => '</div>',
'#type' => 'item',
'#title' => t('Did you mean'),
'#value' => l($new_keywords, $query
->get_path($new_keywords)),
);
}
}
}
}
}
break;
case 'search_block_form':
if (variable_get('apachesolr_search_make_default', 0)) {
if (!isset($form['#submit'])) {
$form['#submit']['apachesolr_search_search_box_form_submit'] = array();
}
else {
$key = isset($form['#submit']['search_box_form_submit']) ? 'search_box_form_submit' : FALSE;
if ($key !== FALSE) {
// Replace the search module's function.
unset($form['#submit'][$key]);
$form['#submit']['apachesolr_search_search_box_form_submit'] = array();
}
}
}
break;
case 'search_theme_form':
apachesolr_search_form_alter('search_block_form', $form);
break;
case 'apachesolr_settings':
$form['advanced']['apachesolr_search_make_default'] = array(
'#type' => 'radios',
'#title' => t('Make Apache Solr Search the default'),
'#default_value' => variable_get('apachesolr_search_make_default', 0),
'#options' => array(
0 => t('Disabled'),
1 => t('Enabled'),
),
'#description' => t('Hides core node search, and makes the search block submit to Apache Solr Search'),
);
$form['advanced']['apachesolr_search_default_previous'] = array(
'#type' => 'value',
'#value' => variable_get('apachesolr_search_make_default', 0),
);
$form['advanced']['apachesolr_search_taxonomy_links'] = array(
'#type' => 'radios',
'#title' => t('Use Apache Solr for taxonomy links'),
'#default_value' => variable_get('apachesolr_search_taxonomy_links', 0),
'#description' => t('Note: Vocabularies that need this behavior need to be checked off on the <a href="@enabled_filters_url">enabled filters</a> settings page', array(
'@enabled_filters_url' => url('admin/settings/apachesolr/enabled-filters'),
)),
'#options' => array(
0 => t('Disabled'),
1 => t('Enabled'),
),
);
$form['advanced']['apachesolr_search_taxonomy_previous'] = array(
'#type' => 'value',
'#value' => variable_get('apachesolr_search_taxonomy_links', 0),
);
$form['apachesolr_search_spellcheck'] = array(
'#type' => 'checkbox',
'#title' => t('Enable spellchecker and suggestions'),
'#default_value' => variable_get('apachesolr_search_spellcheck', FALSE),
'#description' => t('Enable spellchecker and get word suggestions. Also known as the "Did you mean ... ?" feature.'),
);
$form['#submit']['apachesolr_search_build_spellcheck'] = array();
$form['#submit']['apachesolr_search_make_default_submit'] = array();
// Move buttons to the bottom.
$buttons = $form['buttons'];
unset($form['buttons']);
$form['buttons'] = $buttons;
break;
case 'search_admin_settings':
$form['indexing_throttle']['search_cron_limit']['#options']['0'] = '0';
ksort($form['indexing_throttle']['search_cron_limit']['#options']);
break;
}
}