Mercurial > hg > solrsearch
comparison solrsearch_search_blocks.inc @ 0:a2b4f67e73dc default tip
initial
author | Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 08 Jun 2015 10:21:54 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a2b4f67e73dc |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Process variables for search-block-form.tpl.php. | |
5 * | |
6 * The $variables array contains the following arguments: | |
7 * - $form | |
8 * | |
9 * @see search-block-form.tpl.php | |
10 */ | |
11 function template_preprocess_solrsearch_search_block_form(&$variables) { | |
12 $variables['search'] = array(); | |
13 $hidden = array(); | |
14 // Provide variables named after form keys so themers can print each element independently. | |
15 foreach (element_children($variables['form']) as $key) { | |
16 $type = $variables['form'][$key]['#type']; | |
17 if ($type == 'hidden' || $type == 'token') { | |
18 $hidden[] = drupal_render($variables['form'][$key]); | |
19 } | |
20 else { | |
21 $variables['search'][$key] = drupal_render($variables['form'][$key]); | |
22 } | |
23 } | |
24 // Hidden form elements have no value to themers. No need for separation. | |
25 $variables['search']['hidden'] = implode($hidden); | |
26 // Collect all form elements to make it easier to print the whole form. | |
27 $variables['solrsearch_search_form'] = implode($variables['search']); | |
28 } | |
29 | |
30 /** | |
31 * Form builder; Output a search form for the search block's search box. | |
32 * | |
33 * @ingroup forms | |
34 * @see search_box_form_submit() | |
35 * @see search-block-form.tpl.php | |
36 */ | |
37 function solrsearch_search_box($form, &$form_state, $form_id) { | |
38 $form[$form_id] = array( | |
39 '#type' => 'textfield', | |
40 '#title' => t('Search'), | |
41 '#title_display' => 'invisible', | |
42 '#size' => 15, | |
43 '#default_value' => '', | |
44 '#attributes' => array('title' => t('Enter the terms you wish to search for.')), | |
45 ); | |
46 $form['actions'] = array('#type' => 'actions'); | |
47 $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Search')); | |
48 $form['#submit'][] = 'solrsearch_search_box_form_submit'; | |
49 | |
50 return $form; | |
51 } | |
52 | |
53 /** | |
54 * Process a block search form submission. | |
55 */ | |
56 function solrsearch_search_box_form_submit($form, &$form_state) { | |
57 // The search form relies on control of the redirect destination for its | |
58 // functionality, so we override any static destination set in the request, | |
59 // for example by drupal_access_denied() or drupal_not_found() | |
60 // (see http://drupal.org/node/292565). | |
61 if (isset($_GET['destination'])) { | |
62 unset($_GET['destination']); | |
63 } | |
64 | |
65 // Check to see if the form was submitted empty. | |
66 // If it is empty, display an error message. | |
67 // (This method is used instead of setting #required to TRUE for this field | |
68 // because that results in a confusing error message. It would say a plain | |
69 // "field is required" because the search keywords field has no title. | |
70 // The error message would also complain about a missing #title field.) | |
71 if ($form_state['values']['solrsearch_search_block_form'] == '') { | |
72 form_set_error('keys', t('Please enter some keywords.')); | |
73 } | |
74 | |
75 $form_id = $form['form_id']['#value']; | |
76 $info = search_get_default_module_info(); | |
77 if ($info) { | |
78 $form_state['redirect'] = 'solrsearch/' . $info['path'] . '/' . trim($form_state['values'][$form_id]); | |
79 } | |
80 else { | |
81 form_set_error(NULL, t('Search is currently disabled.'), 'error'); | |
82 } | |
83 } | |
84 | |
85 | |
86 | |
87 | |
88 function solrsearch_search_block(){ | |
89 | |
90 $block['content'] = drupal_get_form('solrsearch_search_block_form'); | |
91 return $block; | |
92 | |
93 | |
94 } |