View source
<?php
if (module_exists('apachesolr_search')) {
$plugin = array(
'single' => TRUE,
'title' => t('Apache Solr search form'),
'icon' => 'icon_search.png',
'description' => t('A search form for Apache Solr.'),
'category' => t('Apache Solr Search'),
'defaults' => array(
'path_type' => 'same',
'path' => '',
'override_prompt' => FALSE,
'prompt' => '',
'show_keys' => TRUE,
),
);
}
function apachesolr_panels_apachesolr_form_content_type_render($subtype, $conf, $panel_args, $context) {
$block = new stdClass();
$block->module = 'search';
$block->delta = 'form';
$block->title = '';
$search = apachesolr_panels_static_search_cache();
switch ($conf['path_type']) {
default:
case 'same':
$menu_item = menu_get_item();
$path = $menu_item['href'];
break;
case 'custom':
$path = $conf['path'];
break;
}
if ($conf['show_keys'] && $search) {
$keys = $search['keys'];
}
else {
$keys = '';
}
$prompt = $conf['override_prompt'] ? $conf['prompt'] : NULL;
ctools_include('form');
module_load_include('inc', 'search', 'search.pages');
$form_state = array(
'no_redirect' => TRUE,
'args' => array(
url($path),
$keys,
'apachesolr_panels',
$prompt,
),
);
$block->content = ctools_build_form('apachesolr_panels_search_form', $form_state);
if (empty($block->content)) {
drupal_goto($path . '/' . $form_state['values']['processed_keys']);
}
return $block;
}
function apachesolr_panels_apachesolr_form_content_type_edit_form(&$form, &$form_state) {
$conf = $form_state['conf'];
$form['path_type'] = array(
'#prefix' => '<div class="container-inline">',
'#type' => 'select',
'#title' => t('Path'),
'#options' => array(
'same' => t('Same page'),
'custom' => t('Custom'),
),
'#default_value' => $conf['path_type'],
);
$form['path'] = array(
'#type' => 'textfield',
'#default_value' => $conf['path'],
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-path-type' => array(
'custom',
),
),
'#suffix' => '</div>',
);
$form['override_prompt'] = array(
'#prefix' => '<div class="container-inline">',
'#type' => 'checkbox',
'#default_value' => $conf['override_prompt'],
'#title' => t('Override default prompt'),
);
$form['prompt'] = array(
'#type' => 'textfield',
'#default_value' => $conf['prompt'],
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-override-prompt' => array(
1,
),
),
'#suffix' => '</div>',
);
$form['show_keys'] = array(
'#title' => t('Show current search keys'),
'#type' => 'checkbox',
'#default_value' => $conf['show_keys'],
);
}
function apachesolr_panels_apachesolr_form_content_type_edit_form_submit(&$form, &$form_state) {
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
$form_state['conf'][$key] = $form_state['values'][$key];
}
}
function apachesolr_panels_form_apachesolr_panels_search_form_alter(&$form, &$form_state) {
$form['#validate'] = array(
'search_form_validate',
);
$form['#submit'] = array(
'search_form_submit',
);
if (module_exists('apachesolr_autocomplete')) {
$form['basic']['inline']['keys']['#autocomplete_path'] = 'apachesolr_autocomplete';
}
}