You are here

function i18n_menu_menu_link_update in Internationalization 7

Implements hook_menu_link_update().

1 call to i18n_menu_menu_link_update()
i18n_menu_menu_link_insert in i18n_menu/i18n_menu.module
Implements hook_menu_link_insert()

File

i18n_menu/i18n_menu.module, line 214
Internationalization (i18n) submodule: Menu translation.

Code

function i18n_menu_menu_link_update($link) {

  // Stores the fields to update.
  $fields = array();
  $menu_mode = i18n_menu_mode($link['menu_name']);
  if ($menu_mode & I18N_MODE_TRANSLATE && isset($link['language'])) {

    // Multilingual menu links, translatable, it may be part of a
    // translation set.
    if (i18n_object_langcode($link)) {
      if (!empty($link['translation_set'])) {

        // Translation set comes as parameter, we may be creating a translation,
        // add link to the set.
        $translation_set = $link['translation_set'];
        $translation_set
          ->add_item($link)
          ->save(TRUE);
      }
    }
    elseif ($link['language'] === LANGUAGE_NONE && !empty($link['original_item']['i18n_tsid'])) {
      if ($translation_set = i18n_translation_set_load($link['original_item']['i18n_tsid'])) {
        $translation_set
          ->remove_language($link['original_item']['language']);

        // If there are no links left in this translation set, delete the set.
        // Otherwise update the set.
        $translation_set
          ->update_delete();
      }
      $fields['i18n_tsid'] = 0;
    }
  }

  // For multilingual menu items, always set a language and mark them for
  // 'alter' so they can be processed later by
  // hook_translated_link_menu_alter().
  if ($menu_mode) {
    if (!isset($link['language'])) {
      $link['language'] = LANGUAGE_NONE;
    }
    if (_i18n_menu_link_check_alter($link) && empty($link['options']['alter'])) {
      $fields['options'] = $link['options'];
      $fields['options']['alter'] = TRUE;
    }

    // We cannot unmark links for altering because we don't know what other
    // modules use it for.
  }

  // Update language field if the link has a language value.
  if (isset($link['language'])) {
    $fields['language'] = $link['language'];
  }
  if (!empty($fields)) {

    // If link options are to be updated, they need to be serialized.
    if (isset($fields['options'])) {
      $fields['options'] = serialize($fields['options']);
    }
    db_update('menu_links')
      ->fields($fields)
      ->condition('mlid', $link['mlid'])
      ->execute();
  }

  // Update translatable strings if any for customized links that belong to a
  // localizable menu.
  if (_i18n_menu_link_is_localizable($link)) {
    i18n_string_object_update('menu_link', $link);
  }
  else {
    i18n_string_object_remove('menu_link', $link);
  }
}