You are here

function i18n_menu_menu_update in Internationalization 7

Implements hook_menu_update()

1 call to i18n_menu_menu_update()
i18n_menu_menu_insert in i18n_menu/i18n_menu.module
Implements hook_menu_insert()

File

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

Code

function i18n_menu_menu_update($menu) {

  // Stores the fields of menu links which need an update.
  $update = array();
  if (!isset($menu['i18n_mode'])) {
    $menu['i18n_mode'] = I18N_MODE_NONE;
  }
  if (!($menu['i18n_mode'] & I18N_MODE_LANGUAGE)) {
    $menu['language'] = LANGUAGE_NONE;
  }
  db_update('menu_custom')
    ->fields(array(
    'language' => $menu['language'],
    'i18n_mode' => $menu['i18n_mode'],
  ))
    ->condition('menu_name', $menu['menu_name'])
    ->execute();
  if (!$menu['i18n_mode']) {
    $update['language'] = LANGUAGE_NONE;
  }
  elseif ($menu['i18n_mode'] & I18N_MODE_LANGUAGE) {
    $update['language'] = $menu['language'];
  }

  // Non translatable menu.
  if (!($menu['i18n_mode'] & I18N_MODE_TRANSLATE)) {
    $tsids = db_select('menu_links')
      ->fields('menu_links', array(
      'i18n_tsid',
    ))
      ->groupBy('i18n_tsid')
      ->condition('menu_name', $menu['menu_name'])
      ->condition('customized', 1)
      ->condition('i18n_tsid', 0, '<>')
      ->execute()
      ->fetchCol(0);
    if (!empty($tsids)) {
      foreach ($tsids as $tsid) {
        if ($translation_set = i18n_translation_set_load($tsid)) {
          $translation_set
            ->delete();
        }
      }
    }
    $update['i18n_tsid'] = 0;
  }
  if (!empty($update)) {
    db_update('menu_links')
      ->fields($update)
      ->condition('menu_name', $menu['menu_name'])
      ->condition('customized', 1)
      ->execute();
  }

  // Update strings, always add translation if no language
  if (!i18n_object_langcode($menu)) {
    i18n_string_object_update('menu', $menu);
  }

  // Clear all menu caches.
  menu_cache_clear_all();
}