You are here

function i18n_menu_node_menu_link_alter in Menu translation - Node 7

Implementation of hook_menu_link_alter().

Prepare node translation.

1 call to i18n_menu_node_menu_link_alter()
_i18n_menu_node_item_translations_refresh in ./i18n_menu_node.module
Helper function: actually refresh the menu items returned by the given query.

File

./i18n_menu_node.module, line 205
Menu translation (Node).

Code

function i18n_menu_node_menu_link_alter(&$item) {

  // Check if node translation is enabled.
  $node_translation = !empty($item['i18n_menu_node_translation']) || !isset($item['i18n_menu_node_translation']) && isset($item['options']['translations']);

  // Remove translations: they will be rebuilt below, if necessary.
  unset($item['options']['translations']);

  // If we are handling custom menu items of menu module and no language is set,
  // prepare node translation data.
  if ($node_translation && (empty($item['language']) || $item['language'] == 'und') && $item['module'] == 'menu' && ($nid = _i18n_menu_node_check_path($item))) {

    // Get the translation set id from the menu item path.
    if ($tnid = _i18n_menu_node_get_tnid($nid)) {
      $segments = explode('/', $item['link_path']);

      // We always store the source node nid to allow a correct handling of
      // the active trail in i18n_menu_node_nodeapi() and to improve
      // performance in i18n_menu_node_item_translations_refresh_set().
      $segments[1] = $tnid;

      // Use the source node nid in the link path.
      $item['link_path'] = implode('/', $segments);

      // We store here the current translation set to allow later translation.
      $item['options']['translations'] = i18n_menu_node_get_translations($tnid, NULL);

      // Set alter variables so hook_translated_menu_link_alter() is called
      $item['options']['alter'] = 1;
      $item['localized_options']['alter'] = 1;
    }
    else {

      // No translations available yet but node translation for this menu item
      // is enabled.
      $item['options']['translations'] = array();
    }
  }
}