You are here

function i18n_menu_translation_form in Internationalization 7

Produces a menu translation form.

2 string references to 'i18n_menu_translation_form'
i18n_menu_item_translation_page in i18n_menu/i18n_menu.i18n.inc
Callback for menu item translation tab.
i18n_menu_menu in i18n_menu/i18n_menu.module
Implements hook_menu()

File

i18n_menu/i18n_menu.admin.inc, line 12
Helper functions for menu administration.

Code

function i18n_menu_translation_form($form, $form_state, $translation_set = NULL, $item = NULL) {
  $translation_set = $translation_set ? $translation_set : i18n_translation_set_build('menu_link');
  $form['translation_set'] = array(
    '#type' => 'value',
    '#value' => $translation_set,
  );
  $translations = $translation_set
    ->get_translations();

  // What to do with title? Let's make it a hidden field for now, some tests relay on it
  $form['title'] = array(
    '#type' => 'hidden',
    '#default_value' => $translation_set->title,
  );
  if ($item && ($lang = i18n_object_langcode($item))) {
    $translations[$lang] = $item;
  }
  $item = $item ? $item : array(
    'mlid' => 0,
    'menu_name' => '',
    'plid' => 0,
  );
  $item_lang = i18n_object_langcode($item);
  $form['translations'] = array(
    '#type' => 'fieldset',
    '#title' => t('Translations'),
    '#tree' => TRUE,
    '#description' => t('Enter items that will be considered as translations of each other.'),
  );
  foreach (i18n_language_list() as $langcode => $language_name) {
    if ($langcode == $item_lang) {

      // We've got a predefined item for this language
      $form['translations'][$langcode] = array(
        '#type' => 'value',
        '#value' => $item['menu_name'] . ':' . $item['mlid'],
      );
      $form['translations']['display'] = array(
        '#type' => 'item',
        '#title' => $language_name,
        '#markup' => check_plain($item['link_title']),
      );
    }
    else {

      // Generate a list of possible parents (not including this link or descendants).
      $options = i18n_menu_parent_options(menu_get_menus(), $item, $langcode);
      $default = isset($translations[$langcode]) ? $translations[$langcode]['menu_name'] . ':' . $translations[$langcode]['mlid'] : 'navigation:0';
      if (!isset($options[$default])) {
        $default = 'navigation:0';
      }
      $form['translations'][$langcode] = array(
        '#type' => 'select',
        '#title' => $language_name,
        '#default_value' => $default,
        '#options' => $options,
        '#description' => t('The maximum depth for a link and all its children is fixed at !maxdepth. Some menu links may not be available as parents if selecting them would exceed this limit.', array(
          '!maxdepth' => MENU_MAX_DEPTH,
        )),
        '#attributes' => array(
          'class' => array(
            'menu-title-select',
          ),
        ),
      );
    }
  }
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['update'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  if (!empty($translation_set->tsid)) {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
    );
  }
  return $form;
}