function page_manager_search_menu_alter in Chaos Tool Suite (ctools) 6
Same name and namespace in other branches
- 7 page_manager/plugins/tasks/search.inc \page_manager_search_menu_alter()
Callback defined by page_manager_search_page_manager_tasks().
Alter the search tabs to work with page manager. The search flow is quite odd, and tracing through the code takes hours to realize that the tab you click on does not normally actually handle the search. This tries to account for that.
Note to module authors: This tends to work a lot better with modules that override their own search pages if their _alter runs *before* this one.
1 string reference to 'page_manager_search_menu_alter'
- page_manager_search_page_manager_tasks in page_manager/
plugins/ tasks/ search.inc - Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for more information.
File
- page_manager/
plugins/ tasks/ search.inc, line 56 - Handle the 'node view' override task.
Code
function page_manager_search_menu_alter(&$items, $task) {
// We are creating two sets of tabs. One set is for searching without
// keywords. A second set is for searching *with* keywords. This
// is necessary because search/node/% and search/node need to be
// different due to the way the search menu items function.
// Go through each search module item.
foreach (module_implements('search') as $name) {
// Do not bother with search menu items that should not have search tabs.
if (!module_invoke($name, 'search', 'name', NULL, TRUE)) {
continue;
}
// Put these items under the default search tab which is node.
$items["search/{$name}/%menu_tail"]['tab_parent'] = "search/node/%menu_tail";
$items["search/{$name}/%menu_tail"]['tab_root'] = "search/node/%menu_tail";
$callback = $items["search/{$name}/%menu_tail"]['page callback'];
// Even if a search page is not implemented, we need to add an extra
// entry anyway, for two reasons.
//
// 1) The 'search' menu entry actually handles all entries by default
// and that is going to be bad if the node search is overridden and
// 2) We need to have dual entries to make sure that the tabs are right.
if (variable_get('page_manager_search_disabled_' . $name, TRUE) || $callback != 'search_view' && !variable_get('page_manager_override_anyway', FALSE)) {
$items["search/{$name}"] = $items["search/{$name}/%menu_tail"];
// Put these items under the real search tab.
$items["search/{$name}"]['tab_parent'] = 'search';
$items["search/{$name}"]['tab_root'] = 'search';
if ($name == 'node') {
$items["search/{$name}"]['type'] = MENU_DEFAULT_LOCAL_TASK;
// The default tab should always be left weighted. Because of the way
// menu sorts, this item tends to float around if not weighted.
$items["search/{$name}"]['weight'] = -10;
$items["search/{$name}/%menu_tail"]['weight'] = -10;
}
if ($callback == 'search_view' || variable_get('page_manager_override_anyway', FALSE)) {
$items["search/{$name}/%menu_tail"]['page callback'] = 'page_manager_search_view';
$items["search/{$name}/%menu_tail"]['file path'] = $task['path'];
$items["search/{$name}/%menu_tail"]['file'] = $task['file'];
}
continue;
}
if ($callback == 'search_view' || variable_get('page_manager_override_anyway', FALSE)) {
$items["search/{$name}/%menu_tail"]['page callback'] = 'page_manager_search_page';
$items["search/{$name}/%menu_tail"]['file path'] = $task['path'];
$items["search/{$name}/%menu_tail"]['file'] = $task['file'];
// Add a version that doesn't contain the menu tail for the no keywords
// version. Ordinarily this works because the top level 'search' just
// passes through.
$items["search/{$name}"] = $items["search/{$name}/%menu_tail"];
$items["search/{$name}/%menu_tail"]['page arguments'] = array(
1,
2,
);
// Put these items under the real search tab.
$items["search/{$name}"]['tab_parent'] = 'search';
$items["search/{$name}"]['tab_root'] = 'search';
// Content search is the default search link, so we have to override
// the default task as well.
if ($name == 'node') {
$items["search/{$name}"]['type'] = MENU_DEFAULT_LOCAL_TASK;
// The default tab should always be left weighted. Because of the way
// menu sorts, this item tends to float around if not weighted.
$items["search/{$name}"]['weight'] = -10;
$items["search/{$name}/%menu_tail"]['weight'] = -10;
$items["search"]['page callback'] = 'page_manager_search_page';
$items["search"]['page arguments'] = array(
'node',
);
$items["search"]['file path'] = $task['path'];
$items["search"]['file'] = $task['file'];
}
}
else {
// automatically disable this task if it cannot be enabled.
variable_set('page_manager_search_disabled_' . $name, TRUE);
if (!empty($GLOBALS['page_manager_enabling_search'])) {
drupal_set_message(t('Page manager module is unable to enable search/@name/%menu_tail because some other module already has overridden with %callback.', array(
'%callback' => $callback,
'@name' => $name,
)), 'error');
}
}
}
}