You are here

function i18n_taxonomy_form_alter in Internationalization 7

Implements hook_form_alter().

This is the place to add language fields to all forms.

@ TO DO The vocabulary form needs some javascript.

File

i18n_taxonomy/i18n_taxonomy.module, line 903
i18n taxonomy module

Code

function i18n_taxonomy_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'taxonomy_overview_vocabularies':
      $vocabularies = taxonomy_get_vocabularies();
      foreach ($vocabularies as $vocabulary) {
        if (i18n_object_langcode($vocabulary)) {
          $form[$vocabulary->vid]['name']['#markup'] .= ' (' . i18n_language_name($vocabulary->language) . ')';
        }
      }
      break;
    case 'taxonomy_overview_terms':

      // We check for vocabulary object first, because when confirming alphabetical ordering it uses the same form
      if (!empty($form['#vocabulary']) && i18n_taxonomy_vocabulary_mode($form['#vocabulary']->vid) & I18N_MODE_TRANSLATE) {
        foreach (element_children($form) as $key) {
          if (isset($form[$key]['#term']) && ($lang = i18n_object_langcode($form[$key]['#term']))) {
            $form[$key]['view']['#suffix'] = ' (' . i18n_language_name($lang) . ')';
          }
        }
      }
      break;
    case 'search_form':

      // Localize category selector in advanced search form.
      if (!empty($form['advanced']) && !empty($form['advanced']['category'])) {
        i18n_taxonomy_form_all_localize($form['advanced']['category']);
      }
      break;
  }
}