You are here

function i18ntaxonomy_node_form in Internationalization 6

Handle node form taxonomy.

1 call to i18ntaxonomy_node_form()
i18ntaxonomy_form_alter in i18ntaxonomy/i18ntaxonomy.module
Implementation of hook_form_alter().

File

i18ntaxonomy/i18ntaxonomy.module, line 530
i18n taxonomy module

Code

function i18ntaxonomy_node_form(&$form) {
  $node = $form['#node'];
  if (!isset($node->taxonomy)) {
    $terms = taxonomy_node_get_terms($node);
  }
  else {
    $terms = $node->taxonomy;
  }

  // Regenerate the whole field for translatable vocabularies.
  foreach (element_children($form['taxonomy']) as $vid) {
    if ($vid == 'tags') {

      // Special treatment for tags, add some help texts
      foreach (element_children($form['taxonomy']['tags']) as $vid) {
        $type = i18ntaxonomy_vocabulary($vid);
        if ($type == I18N_TAXONOMY_LOCALIZE || $type == I18N_TAXONOMY_TRANSLATE) {
          $form['taxonomy']['tags'][$vid]['#title'] = i18ntaxonomy_translate_vocabulary_name($vid, $form['taxonomy']['tags'][$vid]['#title']);
          $form['taxonomy']['tags'][$vid]['#description'] = i18nstrings("taxonomy:vocabulary:{$vid}:help", $form['taxonomy']['tags'][$vid]['#description']);
        }
        if ($type == I18N_TAXONOMY_LOCALIZE) {
          $form['taxonomy']['tags'][$vid]['#description'] .= ' ' . t('This is a localizable vocabulary, so only terms in %language are allowed here.', array(
            '%language' => language_default('name'),
          ));
        }
      }
    }
    elseif (is_numeric($vid) && i18ntaxonomy_vocabulary($vid) == I18N_TAXONOMY_LOCALIZE) {

      // Rebuild this vocabulary's form.
      $vocabulary = taxonomy_vocabulary_load($vid);

      // Extract terms belonging to the vocabulary in question.
      $default_terms = array();
      foreach ($terms as $term) {
        if ($term->vid == $vid) {
          $default_terms[$term->tid] = $term;
        }
      }
      $form['taxonomy'][$vid] = i18ntaxonomy_vocabulary_form($vocabulary->vid, array_keys($default_terms));
      $form['taxonomy'][$vid]['#weight'] = $vocabulary->weight;
      $form['taxonomy'][$vid]['#required'] = $vocabulary->required;
      $form['taxonomy'][$vid]['#description'] = i18nstrings("taxonomy:vocabulary:{$vid}:help", $vocabulary->help);
    }
    elseif (is_numeric($vid) && i18ntaxonomy_vocabulary($vid) == I18N_TAXONOMY_TRANSLATE) {

      // Rebuild this vocabulary's form.
      $vocabulary = taxonomy_vocabulary_load($vid);
      $form['taxonomy'][$vid]['#title'] = i18ntaxonomy_translate_vocabulary_name($vid, $vocabulary->name);
      $form['taxonomy'][$vid]['#description'] = i18nstrings("taxonomy:vocabulary:{$vid}:help", $vocabulary->help);
    }
  }
}