You are here

function entity_translation_i18n_menu_node_menu_item_translate in Entity Translation 7

Replace the menu item on the given node with a localized version.

If the menu item is replaced by a different menu item from the translation set, the original item is stored in $node->source_menu.

Parameters

$node: A node object, with a menu item ($node->menu).

$langcode: The language into which the menu item should be translated.

1 call to entity_translation_i18n_menu_node_menu_item_translate()
entity_translation_i18n_menu_node_prepare in entity_translation_i18n_menu/entity_translation_i18n_menu.module
Implements hook_node_prepare().

File

entity_translation_i18n_menu/entity_translation_i18n_menu.module, line 266
The menu specific translation functions and hook implementations.

Code

function entity_translation_i18n_menu_node_menu_item_translate($node, $langcode) {

  // Localization.
  if ($node->menu['language'] == LANGUAGE_NONE) {
    _i18n_menu_link_localize($node->menu, $langcode);

    // Update properties 'link_title' and 'options.attributes.title' which are
    // used for the node menu form; i18n_menu_link_localize only localizes
    // rendered properties 'title' and 'localized_options.attributes.title'.
    $node->menu['link_title'] = $node->menu['title'];
    $node->menu['options']['attributes']['title'] = isset($node->menu['localized_options']['attributes']['title']) ? $node->menu['localized_options']['attributes']['title'] : '';
  }
  else {
    $menu = NULL;
    if (!empty($node->menu['i18n_tsid']) && ($translation_set = i18n_menu_translation_load($node->menu['i18n_tsid']))) {

      // Load menu item from translation set.
      $menu = $translation_set
        ->get_item($langcode);

      // Set parent_depth_limit (required on node forms).
      if (!empty($menu) && !isset($menu['parent_depth_limit'])) {
        $menu['parent_depth_limit'] = _menu_parent_depth_limit($menu);
      }

      // Make sure the menu item is not set to hidden; i18n_menu automatically
      // hides any menu items not matching the current interface language.
      if (!empty($menu)) {
        $menu['hidden'] = FALSE;
      }
    }

    // Replace the menu item with the translated version, or null if there is
    // no translated item. Store the original one in $node->source_menu.
    $node->source_menu = $node->menu;
    $node->menu = $menu;
  }
}