I have a content type Organizations which is an OG Group. I would like to change the default tab name "View" only for this OG group(or content type). Tab tamer module helps with it but it does not allow the change of the name of tabs for a specific content type.

I use sky theme(an Adaptive theme). I wrote the following code in the theme template file,

function sky_preprocess_page(&$vars) {
  if ($vars['node']->type == 'organization') {
    foreach($vars['tabs']['#primary'] AS $index => $tab) {
      if($tab['#link']['title'] == t('View')) {
        $vars['tabs']['#primary'][$index]['#link']['title'] = t('Organization Home');
      }
    }
  }
}

But this doesn't help too

  • basically tabs are created by menu system, so I think we may trying to use hook_menu_alter to change the tab title, may be using uri args as "if" statement – svetlio Oct 21 '12 at 8:28
up vote 6 down vote accepted

You can use hook_menu_alter() to change the name of tabs for a specific content type. For example:

/**
 * Implements hook_menu_alter().
 */
function MYMODULE_menu_alter(&$items) {
  unset($items['node/%node/view']['title']);
  $items['node/%node/view']['title callback'] = 'MYMODULE_view_tab_title';
  $items['node/%node/view']['title arguments'] = array(1);
}

function MYMODULE_view_tab_title($node) {
  if ($node->type == 'organization') {
    return t('Organization Home');
  }
  return t('View');
}

Remember clear Drupal cache.

  • It works Thanks :) – Jayaram Oct 22 '12 at 14:10

There is a module for that: Tab Name Tweaker. Here is a quote about it (from the module's project page):

Allows admins to override the name of the 'View' and 'Edit' tab on node pages.

Possible use cases:

  • 'View' or 'Edit' is not descriptive enough.
  • Organic Groups: when the normal 'View' tab serves as an overview or landing page rather than a specific piece of content.

See theme_menu_local_task().

Here's how you can change the "View" tab link to something else based on node's content type:

function sky_menu_local_task(&$variables) {
  $link = $variables['element']['#link'];

  // Rename the "View" tab for certain node types
  // Check if the link title is "View"
  if ($link['title'] == t('View')) {
    // Make sure we are on single node page
    if (arg(0) == 'node' && arg(1)) {
      $node = node_load(arg(1));
      // Do this for specific content types
      if ($node->type == 'page') {
        $link['title'] = t('Check me out');
      }
    }
  }

  // Continue building the local task link
  $link_text = $link['title'];

  if (!empty($variables['element']['#active'])) {
    // Add text to indicate active tab for non-visual users.
    $active = '<span class="element-invisible">' . t('(active tab)') . '</span>';

    // If the link does not contain HTML already, check_plain() it now.
    // After we set 'html'=TRUE the link will not be sanitized by l().
    if (empty($link['localized_options']['html'])) {
      $link['title'] = check_plain($link['title']);
    }
    $link['localized_options']['html'] = TRUE;
    $link_text = t('!local-task-title!active', array('!local-task-title' => $link['title'], '!active' => $active));
  }

  return '<li' . (!empty($variables['element']['#active']) ? ' class="active"' : '') . '>' . l($link_text, $link['href'], $link['localized_options']) . "</li>\n";

}

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.