To add a 'search all domains' checkbox on the advanced search form i created a custom module
Add the checkbox to the advanced search form:
/**
* Implements hook_form_alter().
*/
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
// change the search form to search all domains
if (isset($_GET['search_all_domains']) && $_GET['search_all_domains'] == 1) {
$default_value = 1;
}
else {
$default_value = 0;
}
if ($form_id == "search_form") {
$form['advanced']['all_domains'] = array(
'#type' => 'checkbox',
'#title' => t('Search all domains'),
'#default_value' => $default_value,
);
$form['#submit'][] = "MYMODULE_search_form_submit";
}
}
Add a $_GET value to the search url in the submit handler:
/**
* Submit handler for search_form
*/
function MYMODULE_search_form_submit($form, &$form_state) {
// add the all_domains variable to the redirect
if ($form_state['values']['all_domains']) {
$form_state['redirect'] = array($form_state['redirect'], array('query' => array('search_all_domains' => 1)));
}
}
If the $_GET variable contains 'search_all_domains=1' grant access to all domains
/**
* Implements hook_node_grants_alter().
*/
function MYMODULE_node_grants_alter(&$grants, $account, $op) {
if (search_is_active() && isset($_GET['search_all_domains']) && $_GET['search_all_domains'] == 1 && $op == 'view') {
$grants['domain_all'] = array(0);
}
}
Now result for all domains are shown in the search result.
The url for the results still need to be rewritten:
/**
* implements hook_preprocess_search_result
* rewrite url to be domain-specific
*/
function MYMODULE_preprocess_search_result(&$variables) {
global $language;
if ($variables['module'] == 'node') {
$domain = domain_get_node_match($variables['result']['node']->nid);
$variables['result']['link'] = $domain['path'] . "node/" . $variables['result']['node']->nid;
}
$result = $variables['result'];
$variables['url'] = check_url($result['link']);
$variables['title'] = check_plain($result['title']);
if (isset($result['language']) && $result['language'] != $language->language && $result['language'] != LANGUAGE_NONE) {
$variables['title_attributes_array']['xml:lang'] = $result['language'];
$variables['content_attributes_array']['xml:lang'] = $result['language'];
}
$info = array();
if (!empty($result['module'])) {
$info['module'] = check_plain($result['module']);
}
if (!empty($result['user'])) {
$info['user'] = $result['user'];
}
if (!empty($result['date'])) {
$info['date'] = format_date($result['date'], 'short');
}
if (isset($result['extra']) && is_array($result['extra'])) {
$info = array_merge($info, $result['extra']);
}
// Check for existence. User search does not include snippets.
$variables['snippet'] = isset($result['snippet']) ? $result['snippet'] : '';
// Provide separated and grouped meta information..
$variables['info_split'] = $info;
$variables['info'] = implode(' - ', $info);
$variables['theme_hook_suggestions'][] = 'search_result__' . $variables['module'];
}
Now it is possible for a user to check 'Search all domains'.
Search results will contain all nodes found for every domain.
If a result is clicked, the node is shown in it's main domain.
Comments
Comment #1
agentrickardhttp://drupal.org/patch/create
Comment #2
agentrickardThis is actually problematic. See #1362382: Menus of all domains combine after searching
Comment #2.0
agentrickardremoved language from rewritten link
Comment #3
agentrickard