Permalink
Browse files

Fixed issues with taxonomy forms

  • Loading branch information...
1 parent a0dfaff commit edd8bd3358cd7b3e851c246328208a3f5938af94 Jose Reyero committed Feb 12, 2011
Showing with 13 additions and 7 deletions.
  1. +5 −2 i18n.module
  2. +8 −5 i18n_taxonomy/i18n_taxonomy.module
View
@@ -241,13 +241,16 @@ function i18n_context_language() {
* Get object language code
*
* @param $object
- * Object or array
+ * Object or array having language field or plain language field
*/
function i18n_object_langcode($object, $field = 'language') {
if (is_object($object)) {
return !empty($object->$field) && $object->$field != LANGUAGE_NONE ? $object->$field : FALSE;
}
- else {
+ elseif (is_array($object)) {
return !empty($object[$field]) && $object[$field] != LANGUAGE_NONE ? $object[$field] : FALSE;
}
+ else {
+ return $object && $object != LANGUAGE_NONE ? $object : FALSE;
+ }
}
@@ -434,17 +434,17 @@ function i18n_taxonomy_form_alter(&$form, $form_state, $form_id) {
case 'taxonomy_overview_vocabularies':
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $vocabulary) {
- if ($vocabulary->language) {
- $form[$vocabulary->vid]['types']['#value'] .= ' ('. i18n_language_name($vocabulary->language) .')';
+ if (i18n_object_langcode($vocabulary)) {
+ $form[$vocabulary->vid]['name']['#markup'] .= ' ('. i18n_language_name($vocabulary->language) .')';
}
}
break;
case 'taxonomy_overview_terms':
if (i18n_taxonomy_vocabulary_mode($form['#vocabulary']->vid) & I18N_MODE_TRANSLATE) {
foreach (element_children($form) as $key) {
- if (isset($form[$key]['#term']) && ($lang = $form[$key]['#term']->language)) {
- $form[$key]['view']['#value'] .= ' ('. i18n_language_name($lang) .')';
+ if (isset($form[$key]['#term']) && ($lang = i18n_object_langcode($form[$key]['#term']))) {
+ $form[$key]['view']['#suffix'] = ' ('. i18n_language_name($lang) .')';
}
}
}
@@ -465,8 +465,11 @@ function i18n_taxonomy_form_alter(&$form, $form_state, $form_id) {
}
}
+/**
+ * Validate multilingual options for vocabulary form
+ */
function i18n_taxonomy_form_vocabulary_validate($form, &$form_state) {
- $language = !empty($form_state['values']['language']) ? $form_state['values']['language'] : '';
+ $language = i18n_object_langcode($form_state['values']['language']);
$mode = $form_state['values']['i18n_mode'];
if ($mode != I18N_MODE_LANGUAGE && $language) {
form_set_error('language', t('Setting a vocabulary language only makes sense in the "Set language to vocabulary" translation mode. Either change to this mode or do not select a language.'));

0 comments on commit edd8bd3

Please sign in to comment.