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