You are here

function menu_token_translated_menu_link_alter in Menu Token 6

Same name and namespace in other branches
  1. 7 menu_token.module \menu_token_translated_menu_link_alter()

Implementation of hook_translated_menu_link().

File

./menu_token.module, line 9

Code

function menu_token_translated_menu_link_alter(&$item, $map) {
  $mlid = $item['mlid'];
  $menu_token_item = menu_token_get($mlid);

  // Check whether we should replace the path.
  if (isset($menu_token_item)) {

    // If item is generated by admin menu module, tokens should not be replaced and
    // indicator that tokens are used should be shown.
    if (_menu_token_menu_admin($item)) {
      $item['title'] .= theme('menu_token_uses_tokens');
      $item['localized_options']['html'] = TRUE;
    }
    else {

      // Replace with tokens.
      $item['title'] = token_replace($item['title'], 'global');
      $item['link_path'] = token_replace($menu_token_item['link_path'], 'global');
      $item['href'] = $item['link_path'];

      // Override active trail if showing front page but translated link is not to front page.
      // NOTE: This relies on any parent of a tokenised menu item having "option" flag "alter" set,
      // which is most easily achieved by setting it to use token translation but not specifying a token.
      // Otherwise parent does not get processed through this function and because its untranslated child has
      // an href of <front>, the menu system thinks it is part of the active trail to the front page.
      if (drupal_is_front_page() && $item['href'] != drupal_get_normal_path(variable_get('site_frontpage', 'node'))) {
        $item['in_active_trail'] = FALSE;
      }

      // Check whether path is external.
      if (menu_path_is_external($item['link_path'])) {
        return;
      }

      // Load menu_item and check access.
      if ($menu_item = menu_get_item($item['link_path'])) {
        $item['access'] = $menu_item['access'];
        return;
      }
      $item['access'] = FALSE;
    }
  }
}