diff --git a/entity_translation.install b/entity_translation.install index 0253e84..9d49212 100644 --- a/entity_translation.install +++ b/entity_translation.install @@ -446,3 +446,25 @@ function entity_translation_update_7007() { // be permanently lost or corrupted. See https://www.drupal.org/node/2396103. variable_set('entity_translation_revision_enabled', FALSE); } + +/** + * Enable Entity Translation for taxonomy vocabularies having terms translated + * through it. + */ +function entity_translation_update_7008() { + // According to EXPLAIN joining {taxonomy_vocabulary} here makes the query + // perform way worse, so we just split into two quick ones. + $query = "SELECT t.vid + FROM {entity_translation} et + JOIN {taxonomy_term_data} t ON et.entity_type = 'taxonomy_term' AND et.entity_id = t.tid AND et.source != '' + GROUP BY t.vid"; + $vids = db_query($query)->fetchCol(); + $query = "SELECT v.machine_name FROM {taxonomy_vocabulary} v WHERE v.vid IN (:vids)"; + $names = db_query($query, array(':vids' => $vids))->fetchCol(); + + $info = variable_get('entity_translation_taxonomy', array()); + foreach ($names as $name) { + $info[$name] = TRUE; + } + variable_set('entity_translation_taxonomy', $info); +} diff --git a/entity_translation.node.inc b/entity_translation.node.inc index 2a23121..99e7b14 100644 --- a/entity_translation.node.inc +++ b/entity_translation.node.inc @@ -46,7 +46,6 @@ function entity_translation_node_menu_alter(&$items, $backup) { $page_arguments = array_merge(array('node', 1, $callback), $item['page arguments']); } else { - $callback = FALSE; $access_arguments = array(1); $page_arguments = array('node', 1); } diff --git a/entity_translation.taxonomy.inc b/entity_translation.taxonomy.inc index 1acde3a..97210f9 100644 --- a/entity_translation.taxonomy.inc +++ b/entity_translation.taxonomy.inc @@ -30,7 +30,6 @@ function entity_translation_taxonomy_term_menu_alter(&$items, $backup) { $page_arguments = array_merge(array('taxonomy_term', 2, $callback), $item['page arguments']); } else { - $callback = FALSE; $access_arguments = array(2); $page_arguments = array('taxonomy_term', 2); } @@ -44,7 +43,7 @@ function entity_translation_taxonomy_term_menu_alter(&$items, $backup) { } /** - * Node specific access callback. + * Taxonomy term specific access callback. */ function entity_translation_taxonomy_term_tab_access() { $args = func_get_args(); @@ -63,16 +62,20 @@ function entity_translation_taxonomy_term_tab_access() { */ function entity_translation_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) { if (entity_translation_enabled('taxonomy_term')) { + $name = $form_state['vocabulary']->machine_name; if (isset($form['i18n_translation']['i18n_mode'])) { $args = array('!url' => url('admin/config/regional/entity_translation')); $form['i18n_translation']['i18n_mode']['#options'][I18N_MODE_ENTITY_TRANSLATION] = t('Field translation. Term fields will be translated through the Entity translation module.', $args); + if (entity_translation_enabled_bundle('taxonomy_term', $name)) { + $form['i18n_translation']['i18n_mode']['#default_value'] = I18N_MODE_ENTITY_TRANSLATION; + } } else { $form['entity_translation_taxonomy'] = array( '#title' => t('Enable field translation'), '#type' => 'checkbox', '#prefix' => '', - '#default_value' => entity_translation_enabled('taxonomy_term', $form_state['vocabulary']->machine_name), + '#default_value' => entity_translation_enabled('taxonomy_term', $name), ); } $form['#submit'][] = 'entity_translation_form_taxonomy_form_vocabulary_submit'; diff --git a/includes/translation.handler.taxonomy_term.inc b/includes/translation.handler.taxonomy_term.inc index e4a3bba..521eb4f 100644 --- a/includes/translation.handler.taxonomy_term.inc +++ b/includes/translation.handler.taxonomy_term.inc @@ -21,6 +21,8 @@ class EntityTranslationTaxonomyTermHandler extends EntityTranslationDefaultHandl public function getLanguage() { if (isset($this->entity->vid) && module_exists('i18n_taxonomy')) { $mode = i18n_taxonomy_vocabulary_mode($this->entity->vid); + // We support also terms having no translation enabled, since they can + // just be language-aware. if ($mode == I18N_MODE_NONE || $mode == I18N_MODE_ENTITY_TRANSLATION) { $translations = $this->getTranslations(); if (!empty($translations->original)) {