i18ntaxonomy_form_alter(&$form, $form_state, $form_id)
contributions/i18n/i18ntaxonomy/i18ntaxonomy.module, line 277
Implementation of hook_form_alter
This is the place to add language fields to all forms
@ TO DO The vocabulary form needs some javascript
<?php
function i18ntaxonomy_form_alter(&$form, $form_state, $form_id) {
switch($form_id){
case 'taxonomy_overview_vocabularies':
$vocabularies = taxonomy_get_vocabularies();
$languages = locale_language_list('name');
foreach ($vocabularies as $vocabulary) {
if ($vocabulary->language) {
$form[$vocabulary->vid]['types']['#value'] .= ' ('.$languages[$vocabulary->language].')';
}
}
break;
case 'taxonomy_overview_terms':
$mode = i18ntaxonomy_vocabulary($form['#vocabulary']['vid']);
if ($mode == I18N_TAXONOMY_TRANSLATE) {
$languages = locale_language_list('name');
foreach (element_children($form) as $key) {
if (isset($form[$key]['#term']) && ($lang = $form[$key]['#term']['language'])) {
$form[$key]['view']['#value'] .= ' ('.$languages[$lang].')';
}
}
}
break;
case 'taxonomy_form_vocabulary': // Taxonomy vocabulary
if (!empty($form['vid']['#value'])) {
$vocabulary = taxonomy_vocabulary_load($form['vid']['#value']);
$mode = i18ntaxonomy_vocabulary($vocabulary->vid);
} else {
$vocabulary = NULL;
$mode = I18N_TAXONOMY_NONE;
}
$form['i18n'] = array(
'#type' => 'fieldset',
'#title' => t('Multilingual options'),
'#collapsible' => TRUE,
'#weight' => 0,
);
$form['i18n']['i18nmode'] = array(
'#type' => 'radios',
'#title' => t('Translation mode'),
'#options' => _i18ntaxonomy_vocabulary_options(),
'#default_value' => $mode,
'#description' => t('For localizable vocabularies, to have all terms available for translation visit the !locale-refresh page', array('!locale-refresh' => l(t('translation refresh'), 'admin/build/translate/refresh') )),
);
$form['i18n']['language'] = array(
'#type' => 'select',
'#title' => t('Language'),
'#default_value' => $vocabulary && !empty($vocabulary->language) ? $vocabulary->language : '',
'#options' => array('' => '') + locale_language_list('name'),
'#description' => t('Language for this vocbulary. If set, it will apply to all terms in this vocabulary.'),
'#disabled' => ($vocabulary && $mode != I18N_TAXONOMY_LANGUAGE),
);
break;
case 'taxonomy_form_term': // Taxonomy term
$vocabulary = (object)$form['#vocabulary'];
$term = (object)$form['#term'];
// Add language field or not depending on taxonomy mode
switch (i18ntaxonomy_vocabulary($vocabulary->vid)) {
case I18N_TAXONOMY_TRANSLATE:
$form['identification']['language'] = array(
'#type' => 'select',
'#title' => t('Language'),
'#default_value' => isset($term) && !empty($term->language) ? $term->language : '',
'#options' => array('' => '') + locale_language_list('name'),
'#description' => t('This term belongs to a multilingual vocabulary. You can set a language for it.'),
);
break;
case I18N_TAXONOMY_LANGUAGE:
$form['language'] = array('#type' => 'value', '#value' => $vocabulary->language);
$form['identification']['language_info'] = array('#value' => t('All terms in this vocabulary have a fixed language: %language', array('%language' => i18n_language_property($vocabulary->language, 'name'))));
break;
case I18N_TAXONOMY_LOCALIZE:
$form['language'] = array('#type' => 'value', '#value' => '');
$form['identification']['name']['#description'] .= ' <strong>'.t('This name be localizable').'</strong>';
$form['identification']['description']['#description'] .= ' <strong>'.t('This description will be localizable').'</strong>';
break;
case I18N_TAXONOMY_NONE:
default:
$form['language'] = array('#type' => 'value', '#value' => '');
break;
}
break;
default:
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id
&& ($node = $form['#node']) && isset($form['taxonomy']) ) {
// Node form. Translate vocabularies
i18ntaxonomy_node_form($form);
}
}
}
?>