function _jump_menu_render_block in Better Jump Menus 7
Same name and namespace in other branches
- 8 jump_menu.module \_jump_menu_render_block()
Abstract block rendering to be more flexible about when/how this happens.
2 calls to _jump_menu_render_block()
- jump_menu_block_view in ./
jump_menu.module - Display jump menu block.
- jump_menu_block_view_alter in ./
jump_menu.module - Make use of block settings on display.
File
- ./
jump_menu.module, line 210 - Make use of the CTools jump menu and grabs from an existing menu. See: modules/ctools/includes/jump-menu.inc NOTE: Menu items must be checked as "expanded" for traversing to work.
Code
function _jump_menu_render_block($delta, $options = array()) {
// Strip off jump_menu.
$block_name = str_replace('jump_menu-', '', $delta);
// Cache menu list.
static $menus;
if (!isset($menus)) {
$menus = menu_get_menus(TRUE);
}
// Options are always available.
$options['hide'] = isset($options['hide']) ? $options['hide'] : TRUE;
// Allow setting active item.
$settings = _jump_menu_get_settings($delta);
// Allow showing a button via block UI.
if ($settings['show_button']) {
$options['hide'] = FALSE;
$options['button'] = 'Go';
}
else {
$options['hide'] = isset($options['hide']) ? $options['hide'] : TRUE;
$options['button'] = FALSE;
}
// If a menu block.
if (substr($block_name, 0, 2) == 'm_') {
foreach ($menus as $k => $v) {
// Block delta prefix length is 12 chars, leaves 20 for menu name.
// Compare as much fits against the menu portion of the delta.
if (substr($k, 0, 20) == substr($block_name, 2)) {
// Set the title.
$data['subject'] = check_plain($menus[$k]);
// Set default 'choose' text to menu name.
$options['choose'] = isset($options['choose']) ? $options['choose'] : check_plain($menus[$k]);
$data['content'] = jump_menu($k, 0, $options['button'], 0, $options['choose'], $settings['show_current']);
}
}
}
elseif (substr($block_name, 0, 11) == 'local-tasks') {
// Collect the local tasks.
$links = menu_local_tasks(0);
$links_secondary = menu_local_tasks(1);
// Are there any real secondary tasks?
$secondary = count($links_secondary['tabs']['output']) != 0 ? TRUE : FALSE;
if ($links['tabs']['count'] > 0) {
// Add plugin.
ctools_include('jump-menu');
$targets = array();
// Create select list targets.
foreach ($links['tabs']['output'] as $l) {
if ($l['#link']['access'] == TRUE) {
// Set active.
$classes = isset($l['#active']) ? 'active' : '';
$targets[] = array(
'value' => url($l['#link']['href']),
'title' => t($l['#link']['title']),
'#attributes' => array(
'class' => $classes,
),
);
// Do secondary tabs fit with this item?
if ($secondary && $links_secondary['tabs']['output'][0]['#link']['tab_parent_href'] == $l['#link']['href']) {
foreach ($links_secondary['tabs']['output'] as $sl) {
// Set active.
$classes = $l['#active'] ? 'active' : '';
$targets[] = array(
'value' => url($sl['#link']['href']),
'title' => '- ' . t($sl['#link']['title']),
'#attributes' => array(
'class' => $classes,
),
);
}
}
}
}
// Take options and place defaults.
$options['choose'] = isset($options['choose']) ? $options['choose'] : t(JUMP_MENU_DEFAULT_CHOOSE);
// Process setting active item.
if ($settings['show_current']) {
$current_path = base_path() . request_path();
if (!empty($current_path)) {
$options['default_value'] = $current_path;
}
}
// Populate block.
$data['subject'] = t('Local Tasks');
$data['content'] = drupal_get_form('ctools_jump_menu', $targets, $options);
}
else {
$data = FALSE;
}
}
else {
$notice = t('Something is wrong with the Jump Menu module, please report.');
if (variable_get('error_level') > 0) {
drupal_set_message($notice);
}
else {
$message = 'Unable to render Jump Menu block. Likely due to a bad menu delta in the database.';
watchdog('jump_menu', $message, array(), WATCHDOG_ERROR);
drupal_set_message($notice);
}
$data = FALSE;
}
return $data;
}