1

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

1
  • 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
    Commented Oct 21, 2012 at 8:28

4 Answers 4

6

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.

0
1

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.
1
0

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";

}
0

My solution:~

  1. https://www.drupal.org/project/tab_manager tab_manager module

  2. a snippet code(tested with Drupal 10 ):~

    /**

    • Implements hook_menu_local_tasks_alter().

    • change the user account page's tab View text to "test example" */ function showcontent_menu_local_tasks_alter(array &$data,string $route_name, \Drupal\Core\Cache\RefinableCacheableDependencyInterface &$cacheability) { // Check if we're on the user account page and altering the "View" tab.

      if (isset($route_name) && $route_name == 'entity.user.canonical'&& $data['tabs'][0]['entity.user.canonical']['#link']['title'] === 'View') { // Change the title to "Submitted". $data['tabs'][0]['entity.user.canonical']['#link']['title'] = t('test example'); }

    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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