You are here

function om_search_alter in OM Tools 7.2

Same name and namespace in other branches
  1. 8.2 tools/search/search.inc \om_search_alter()
  2. 8 tools/search/search.inc \om_search_alter()
  3. 6 tools/search/search.inc \om_search_alter()
  4. 7 tools/search/search.inc \om_search_alter()

OM Tools Search Form Alters

File

tools/search/search.inc, line 56
Search Tools

Code

function om_search_alter(&$form, &$form_state, $form_id) {
  $search_defaults = $form['om_search_tools_values']['#value'];

  // Make sure the js are added only once
  static $search_form_js = 0;
  static $search_block_js = 0;
  switch ($form_id) {
    case "search_form":
      if (isset($search_defaults['search_switch']) && $search_defaults['search_switch'] == 1) {
        drupal_set_title(t($search_defaults['search_title']));
        $search_label = $search_defaults['search_label'];
        $search_label_text = $search_defaults['search_label_text'];
        $search_size = $search_defaults['search_size'];
        $search_hover = $search_defaults['search_hover'];
        $search_button = $search_defaults['search_button'];
        if ($search_label) {
          unset($form['basic']['keys']['#title']);

          //$form['basic']['keys']['#default_value'] = $search_label_text;
          $search_form_js++;
          if ($search_form_js == 1) {
            drupal_add_js(OM_TOOLS_PATH . '/tools/search/jquery.om_tools_search.js', 'file');
            drupal_add_js("\n              jQuery(document).ready(function(\$){\n                \$('#search-form').om_tools_search({\n                   'form_id'         : 'search_form',\n                   'search_defaults' : { search_label_text : '" . $search_label_text . "'}\n                });   \n              }); \n            ", "inline");
          }
        }
        else {
          $form['basic']['#title'] = $search_label_text;
        }
        $form['basic']['keys']['#size'] = $search_size;
        $form['basic']['keys']['#attributes'] = array(
          'title' => t($search_hover),
        );
        $form['basic']['submit']['#value'] = t($search_button);
      }
      break;
    case "search_block_form":
      if (isset($search_defaults['search_block_switch']) && $search_defaults['search_block_switch'] == 1) {
        $search_block_label = $search_defaults['search_block_label'];
        $search_block_label_text = $search_defaults['search_block_label_text'];
        $search_block_size = $search_defaults['search_block_size'];
        $search_block_hover = $search_defaults['search_block_hover'];
        $search_block_button = $search_defaults['search_block_button'];
        if ($search_block_label) {
          unset($form['search_block_form']['#title']);

          //$form['search_block_form']['#default_value'] = $search_block_label_text;
          $search_block_js++;
          if ($search_block_js == 1) {
            drupal_add_js(OM_TOOLS_PATH . '/tools/search/jquery.om_tools_search.js', 'file');
            drupal_add_js("\n              jQuery(document).ready(function(\$){\n                \$('#search-block-form').om_tools_search({\n                   'form_id'         : 'search_block_form',\n                   'search_defaults' : { search_block_label_text : '" . $search_block_label_text . "'}\n                }); \n              }); \n              ", "inline");
          }
        }
        else {
          $form['search_block_form']['#title'] = $search_block_label_text;
        }
        $form['search_block_form']['#size'] = $search_block_size;
        $form['search_block_form']['#attributes'] = array(
          'title' => t($search_block_hover),
        );
        $form['actions']['submit']['#value'] = t($search_block_button);
      }
      break;
  }
}