Skip to content

Instantly share code, notes, and snippets.

@jacine
Created August 11, 2012 05:23
Show Gist options
  • Save jacine/3321429 to your computer and use it in GitHub Desktop.
Save jacine/3321429 to your computer and use it in GitHub Desktop.
<?php
/**
* Implements hook_menu_local_tasks_alter().
*/
function utils_menu_local_tasks_alter(&$data, $router_item, $root_path) {
// Define the tabs.
$contact = array(
'#theme' => 'menu_local_task',
'#link' => array(
'title' => t('Say Hello'),
'href' => 'contact',
'localized_options' => array(
'attributes' => array(
'title' => t('Drop us a line'),
),
),
),
);
$quote = array(
'#theme' => 'menu_local_task',
'#link' => array(
'title' => t('Get a Quote'),
'href' => 'node/50',
'localized_options' => array(
'attributes' => array(
'title' => t('Get a quote'),
),
),
),
);
// Get the current path.
$current_path = current_path();
// Quote page.
if ($current_path == 'node/50') {
// If the 'View' tab is already there, just alter the title.
if (count($data['tabs'][0]['output'] > 1) && $data['tabs'][0]['output'][0]['#link']['title'] == 'View') {
$data['tabs'][0]['output'][0]['#link']['type'] = MENU_LOCAL_TASK;
$data['tabs'][0]['output'][0]['#link']['title'] = 'Get a quote';
}
// Add it as a new tab.
else {
$data['tabs'][0]['output'][] = $quote;
}
// Add the "Contact" tab.
$data['tabs'][0]['output'][] = $contact;
}
// Contact page.
if ($current_path == 'contact') {
$data['tabs'][0]['output'][] = $quote;
$data['tabs'][0]['output'][] = $contact;
}
// Manually update the 'count' so that the tabs actually print out.
// This must be a core bug?
// @see http://drupal.org/node/1140550
if (in_array($current_path, array('node/50', 'contact'))) {
$data['tabs'][0]['count'] = count($data['tabs'][0]['output']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment