Mercurial > hg > MPIWG-drupal-modules
view sites/all/modules/custom/solrsearch/solrsearch_search_author_block.inc @ 0:015d06b10d37 default tip
initial
author | dwinter |
---|---|
date | Wed, 31 Jul 2013 13:49:13 +0200 |
parents | |
children |
line wrap: on
line source
<?php /** * Form builder; Output a search form for the search block's search box. * * @ingroup forms * @see search_box_form_submit() * @see search-block-form.tpl.php */ function solrsearch_search_author_box($form, &$form_state, $form_id) { $form[$form_id] = array( '#type' => 'textfield', '#title' => t('Search'), '#title_display' => 'invisible', '#size' => 15, '#default_value' => '', '#attributes' => array('title' => t('Enter the terms you wish to search for.')), ); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Search')); $form['#submit'][] = 'solrsearch_search_author_box_form_submit'; return $form; } /** * Process a block search form submission. */ function solrsearch_search_author_box_form_submit($form, &$form_state) { // The search form relies on control of the redirect destination for its // functionality, so we override any static destination set in the request, // for example by drupal_access_denied() or drupal_not_found() // (see http://drupal.org/node/292565). if (isset($_GET['destination'])) { unset($_GET['destination']); } // Check to see if the form was submitted empty. // If it is empty, display an error message. // (This method is used instead of setting #required to TRUE for this field // because that results in a confusing error message. It would say a plain // "field is required" because the search keywords field has no title. // The error message would also complain about a missing #title field.) if ($form_state['values']['solrsearch_search_author_block_form'] == '') { form_set_error('keys', t('Please enter some keywords.')); } $form_id = $form['form_id']['#value']; $info = search_get_default_module_info(); if ($info) { $form_state['redirect'] = 'solrsearch/' . $info['path'] . '/IM_author:' . trim($form_state['values'][$form_id]); } else { form_set_error(NULL, t('Search is currently disabled.'), 'error'); } } /** * Process variables for search-block-form.tpl.php. * * The $variables array contains the following arguments: * - $form * * @see search-block-form.tpl.php */ function template_preprocess_solrsearch_search_author_block_form(&$variables) { $variables['search'] = array(); $hidden = array(); // Provide variables named after form keys so themers can print each element independently. foreach (element_children($variables['form']) as $key) { $type = $variables['form'][$key]['#type']; if ($type == 'hidden' || $type == 'token') { $hidden[] = drupal_render($variables['form'][$key]); } else { $variables['search'][$key] = drupal_render($variables['form'][$key]); } } // Hidden form elements have no value to themers. No need for separation. $variables['search']['hidden'] = implode($hidden); // Collect all form elements to make it easier to print the whole form. $variables['solrsearch_search_form'] = implode($variables['search']); } function solrsearch_search_author_block(){ $block['content'] = drupal_get_form('solrsearch_search_author_block_form'); return $block; }