function i18ntaxonomy_form_alter in Internationalization 6
Same name and namespace in other branches
- 5.3 contrib/i18ntaxonomy.module \i18ntaxonomy_form_alter()
- 5 contrib/i18ntaxonomy.module \i18ntaxonomy_form_alter()
- 5.2 contrib/i18ntaxonomy.module \i18ntaxonomy_form_alter()
Implementation of hook_form_alter().
This is the place to add language fields to all forms.
@ TO DO The vocabulary form needs some javascript.
File
- i18ntaxonomy/
i18ntaxonomy.module, line 363 - i18n taxonomy module
Code
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;
}
drupal_add_js(drupal_get_path('module', 'i18ntaxonomy') . '/i18ntaxonomy.js');
drupal_add_js(array(
'i18ntaxonomy_vocabulary_form' => array(
'I18N_TAXONOMY_LANGUAGE' => I18N_TAXONOMY_LANGUAGE,
),
), 'setting');
$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 <a href="@locale-refresh">translation refresh</a> page.', array(
'@locale-refresh' => url('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 vocabulary. If set, it will apply to all terms in this vocabulary.'),
'#disabled' => $vocabulary && $mode != I18N_TAXONOMY_LANGUAGE,
);
$form['#validate'][] = 'i18ntaxonomy_form_vocabulary_validate';
break;
case 'taxonomy_form_term':
// Taxonomy term
// Check for confirmation forms
if (isset($form_state['confirm_delete']) || isset($form_state['confirm_parents'])) {
return;
}
$vocabulary = (object) $form['#vocabulary'];
$term = (object) $form['#term'];
// Mark form so we can know later when saving the term it came from a taxonomy form
$form['i18ntaxonomy_form'] = array(
'#type' => 'value',
'#value' => 1,
);
// 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 will be localizable. You can translate it using the <a href="@translate-interface">translate interface</a> pages.', array(
'@translate-interface' => url('admin/build/translate'),
)) . '</strong>';
$form['identification']['description']['#description'] .= ' <strong>' . t('This description will be localizable. You can translate it using the <a href="@translate-interface">translate interface</a> pages.', array(
'@translate-interface' => url('admin/build/translate'),
)) . '</strong>';
break;
case I18N_TAXONOMY_NONE:
default:
$form['language'] = array(
'#type' => 'value',
'#value' => '',
);
break;
}
break;
case 'search_form':
// Localize category selector in advanced search form.
if (!empty($form['advanced']) && !empty($form['advanced']['category'])) {
i18ntaxonomy_form_all_localize($form['advanced']['category']);
}
break;
default:
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id && ($node = $form['#node']) && isset($form['taxonomy']) && !variable_get('taxonomy_override_selector', FALSE)) {
// Node form. Translate vocabularies.
i18ntaxonomy_node_form($form);
}
}
}