Hi,

I have three tabs in my search results page : Google (using module google_cse), Content, and Files (using module search_files).

By default, when a user performs a search, the default result is on the "content" tab. I would like the default tab be set to the "Google" tab...

Any clue ?

Cheers,
Jerome

Comments

aaustin’s picture

I would check out hook_menu_alter first.

Here is what I would try - I have done something similar with success recently:

function marc_union_menu_alter(&$menu) {
  $menu['search/node']['type'] = MENU_LOCAL_TASK;
  $menu['search/google_cse']['type'] = MENU_DEFAULT_LOCAL_TASK;
}

Check the exact menu path of the goodle_cse search.

jerome72’s picture

Thank you very much for answering !

I tried this function, but instead of getting my default google tab, it removes the "content" and "google" tabs. I can't figure out why...

I only put this function in my module, I don't know what I missed.

Any idea ?

kid_baco’s picture

I'm also looking to change the default tab. Did you find a way of doing it?

rschwab’s picture

The guy above is right, you need to use hook_menu_alter. I don't know if there is any way to flag a menu tab as the default, but perhaps making its weight lighter would do the trick? Something like:

function yourmodulename_menu_alter(&$items) {
$items['search/google']['weight'] = -10; // The key should be your path to your google search page
}

I'm just a beginner so this is just a suggestion, and may not be the preferred way of doing this.

- Ryan

kid_baco’s picture

Thanks Ryan,

I see that your tweak changes the order of the tabs, but what I was hoping to do was have the search block form actually go to another tab when submitted. For example, say when you submitted the search form and it defaulted to the User tab, as opposed to the Content tab (and therefor the path would be search/user as opposed to search/node).

I'm pretty new to this myself, so it's good to see what you were talking about.

monotaga’s picture

kid_baco,

Any luck on this?

vvvi’s picture

I know this is an old thread, but I hope it will usefull for someone. Add next functions in your module file (the example is shown for modul's name 'search_files' and a path to search 'google_cse', replace it for your case):

/**
* Implementation of hook_form_FORM_ID_alter().
*/
function search_files_form_search_block_form_alter(&$form, &$form_state) {
    $form['#submit'][] = 'search_files_box_form_submit'; // rewrite drupal's function search_box_form_submit($form, &$form_state) 
}

/**
 * Process a block search form submission.
 */
function search_files_box_form_submit($form, &$form_state) {
  if (isset($_REQUEST['destination'])) {
    unset($_REQUEST['destination']);
  }
  if (isset($_REQUEST['edit']['destination'])) {
    unset($_REQUEST['edit']['destination']);
  }

  $form_id = $form['form_id']['#value'];
  $form_state['redirect'] = 'search/google_cse/'. trim($form_state['values'][$form_id]); // HERE WE MAKE A RIGHT REDIRECT
}
Dawn360’s picture

used hook_form_alter() for the first part
and changed 'search/google_cse' to 'search/google'

<?php
/**
* Implementation of hook_form_alter().
*/
function search_files_form_alter((&$form, &$form_state, $form_id) {
  if ($form_id == 'search_form' || $form_id == 'search_theme_form') {
    $form['#submit'][] = 'search_files_submit'; // rewrite drupal's function search_box_submit($form, &$form_state) 
  }
}

/**
 * Process a block search form submission.
 */
function search_files_submit($form, &$form_state) {
  if (isset($_REQUEST['destination'])) {
    unset($_REQUEST['destination']);
  }
  if (isset($_REQUEST['edit']['destination'])) {
    unset($_REQUEST['edit']['destination']);
  }

  $form_id = $form['form_id']['#value'];
  $form_state['redirect'] = 'search/google/'. trim($form_state['values'][$form_id]); // HERE WE MAKE A RIGHT REDIRECT
}
?>
rsharkey’s picture

Here is a custom module I wrote to achieve the desired result you are looking for.

This module adds a setting in your administration theme to check a box to enable this functionality. Leave this option unchecked to use the default "Content" tab.

See the contents of my google_cse_default.module file below:


/**
* Module admin configuration settings
*/

function google_cse_default_form() {

  $form = array();
  
  $form['google_cse_default'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show Google CSE as the default tab for site searches?'),
	'#default_value' => variable_get('google_cse_default', 0),
	'#description' => t('Check this box and save the configuration to show the Google CSE as the default tab for site searches.'),
  );

  return system_settings_form($form);
}

/**
* Module menu setup
*/

function google_cse_default_menu() {

  $items = array();

  $items['admin/settings/google_cse_default'] = array(
    'title' => 'Google CSE Default',
    'description' => 'This module will show Google CSE as the default tab for site searches.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('google_cse_default_form'),
    'access arguments' => array('Administer google cse default settings'),
    'type' => MENU_NORMAL_ITEM,
   );

  return $items;
}

/**
* Display help and module information
* @param path which path of the site we're displaying help
* @param arg array that holds the current path as would be returned from arg() function
* @return help text for the path
*/

function google_cse_default_help($path, $arg) {
  $output = '';  //declare your output variable
  switch ($path) {
    case "admin/help#google_cse_default":
      $output = '<p>'.  t("This module will show Google CSE as the default tab for site searches.") .'</p>';
      break;
  }
  return $output;
} // function google_cse_default_help

/**
* Valid permissions for this module
* @return array
*/
function google_cse_default_perm() {
  return array('Administer google cse default settings');
} // function google_cse_default_perm()

/**
 * Implementation of hook_form_alter()
 *
 *
 */
function google_cse_default_form_alter(&$form, $form_state, $form_id) {

  if ($form_id == 'search_form' || $form_id == 'search_theme_form') {
  
	if (variable_get('google_cse_default', 0)) { 
	
		$form['#submit'][] = 'google_cse_default_submit'; // rewrite drupal's function search_box_submit($form, &$form_state)
		
	}
  }
  
}

/**
 * Process the Google CSE serach redirect
 *
 *
 */
function google_cse_default_submit($form, &$form_state) {
	
	if (variable_get('google_cse_default', 0)) { 
	
	  if (isset($_REQUEST['destination'])) {
		unset($_REQUEST['destination']);
	  }
	  
	  if (isset($_REQUEST['edit']['destination'])) {
		unset($_REQUEST['edit']['destination']);
	  }

	  $form_id = $form['form_id']['#value'];
	  $form_state['redirect'] = 'search/google/'. trim($form_state['values'][$form_id]); // HERE WE MAKE A RIGHT REDIRECT
  
	}
}

In my google_cse_default.info file I set the module to depend upon the google_cse module.

See the contents of my google_cse_default.info file below:

name = Google CSE Default
description = "This module will show Google CSE as the default tab for site searches."
dependencies[] = search
dependencies[] = google_cse
core = 6.x
Pushkar Gaikwad’s picture

Thanks Ryan, this worked. Surprisingly the other solution of "disabling search module and give full permissions to google_cse" didn't worked

glyn.hudson’s picture

Thanks Ryan,
Your custom module works for me making google cse the default search when a search is made from the drupal search box on the top RH corner of my site. However once one search has been made and the results displayed if the user then refines the search in the google search box and clicks search no results are displayed. If I disable the google_cse_default module then this works but google cse is no longer the default search. As anyone got any ideas what could be causing this issue. See for youself at http://openenegymonitor.org.

Thanks a lot,

kmmathis’s picture

I added a new folder to my modules directory, and in it put the module and info files. I enabled the module, and checked the checkbox in the new settings page that was created. I cleared my cache and did a new search, and it still defaults to Content rather than Google. Did you have to change anything to make it work?