diff --git a/entity_translation.admin.inc b/entity_translation.admin.inc
index 3bdf410..6cda85e 100644
--- a/entity_translation.admin.inc
+++ b/entity_translation.admin.inc
@@ -211,8 +211,9 @@ function entity_translation_settings_init($entity_type, $settings = array()) {
*/
function entity_translation_overview($entity_type, $entity, $callback = NULL) {
// Entity translation and node translation share the same system path.
- if ($callback && entity_translation_node($entity_type, $entity)) {
- return entity_translation_overview_callback($callback, $entity);
+ if ($callback && !entity_translation_enabled($entity_type, $entity)) {
+ $args = array_slice(func_get_args(), 3);
+ return entity_translation_overview_callback($callback, $args);
}
$handler = entity_translation_get_handler($entity_type, $entity);
@@ -356,13 +357,13 @@ function entity_translation_overview($entity_type, $entity, $callback = NULL) {
/**
* Calls the appropriate translation overview callback.
*/
-function entity_translation_overview_callback($callback, $entity) {
+function entity_translation_overview_callback($callback, $args) {
if (module_exists($callback['module'])) {
if (isset($callback['file'])) {
$path = isset($callback['file path']) ? $callback['file path'] : drupal_get_path('module', $callback['module']);
require_once DRUPAL_ROOT . '/' . $path . '/' . $callback['file'];
}
- return $callback['page callback']($entity);
+ return call_user_func_array($callback['page callback'], $args);
}
}
diff --git a/entity_translation.module b/entity_translation.module
index 947caff..4dd5047 100644
--- a/entity_translation.module
+++ b/entity_translation.module
@@ -6,6 +6,7 @@
*/
module_load_include('inc', 'entity_translation', 'entity_translation.node');
+module_load_include('inc', 'entity_translation', 'entity_translation.taxonomy');
/**
@@ -23,6 +24,11 @@ define('ENTITY_TRANSLATION_LANGUAGE_CURRENT', 'xx-et-current');
*/
define('ENTITY_TRANSLATION_LANGUAGE_AUTHOR', 'xx-et-author');
+/**
+ * Defines an i18n translation mode for Entity Translation.
+ */
+define('I18N_MODE_ENTITY_TRANSLATION', 0xF0000000);
+
/**
* Implements hook_hook_info().
@@ -105,8 +111,11 @@ function entity_translation_entity_info() {
'translation' => array(
'entity_translation' => array(
'class' => 'EntityTranslationTaxonomyTermHandler',
+ 'access callback' => 'entity_translation_taxonomy_term_tab_access',
+ 'access arguments' => array(1),
'base path' => 'taxonomy/term/%taxonomy_term',
'edit form' => 'term',
+ 'bundle callback' => 'entity_translation_taxonomy_term_enabled_vocabulary',
),
),
);
@@ -507,9 +516,10 @@ function entity_translation_menu_alter(&$items) {
drupal_set_message(t('The entities of type %entity_type do not define a valid path scheme: it will not be possible to translate them.', array('%entity_type' => $info['label'])), 'warning');
}
- // Node-specific menu alterations.
- if ($entity_type == 'node') {
- entity_translation_node_menu_alter($items, $backup);
+ // Entity-type-specific menu alterations.
+ $function = 'entity_translation_' . $entity_type . '_menu_alter';
+ if (function_exists($function)) {
+ $function($items, $backup);
}
}
}
@@ -871,13 +881,6 @@ function entity_translation_field_extra_fields() {
if (entity_translation_enabled($entity_type)) {
$bundles = !empty($info[$entity_type]['bundles']) ? array_keys($info[$entity_type]['bundles']) : array($entity_type);
foreach ($bundles as $bundle) {
- // @todo Clean this up in https://www.drupal.org/node/1661348.
- if ($entity_type == 'taxonomy_term') {
- $vocabulary = taxonomy_vocabulary_machine_name_load($bundle);
- if ($vocabulary && module_invoke('i18n_taxonomy', 'vocabulary_mode', $vocabulary, 4)) {
- continue;
- }
- }
$settings = entity_translation_settings($entity_type, $bundle);
if (empty($settings['hide_language_selector']) && entity_translation_enabled_bundle($entity_type, $bundle) && ($handler = entity_translation_get_handler($entity_type, $bundle))) {
$language_key = $handler->getLanguageKey();
diff --git a/entity_translation.node.inc b/entity_translation.node.inc
index 40d0f5d..2a23121 100644
--- a/entity_translation.node.inc
+++ b/entity_translation.node.inc
@@ -43,14 +43,16 @@ function entity_translation_node_menu_alter(&$items, $backup) {
$callback['file'] = $item['file'];
$callback['module'] = $item['module'];
$access_arguments = array_merge(array(1, $item['access callback']), $item['access arguments']);
+ $page_arguments = array_merge(array('node', 1, $callback), $item['page arguments']);
}
else {
$callback = FALSE;
$access_arguments = array(1);
+ $page_arguments = array('node', 1);
}
$items['node/%node/translate']['page callback'] = 'entity_translation_overview';
- $items['node/%node/translate']['page arguments'] = array('node', 1, $callback);
+ $items['node/%node/translate']['page arguments'] = $page_arguments;
$items['node/%node/translate']['access arguments'] = $access_arguments;
$items['node/%node/translate']['access callback'] = 'entity_translation_node_tab_access';
$items['node/%node/translate']['file'] = 'entity_translation.admin.inc';
diff --git a/entity_translation.taxonomy.inc b/entity_translation.taxonomy.inc
new file mode 100644
index 0000000..1acde3a
--- /dev/null
+++ b/entity_translation.taxonomy.inc
@@ -0,0 +1,93 @@
+ 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);
+ }
+ 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),
+ );
+ }
+ $form['#submit'][] = 'entity_translation_form_taxonomy_form_vocabulary_submit';
+ }
+}
+
+/**
+ * Submit handler for the taxonomy vocabulary form.
+ */
+function entity_translation_form_taxonomy_form_vocabulary_submit($form, &$form_state) {
+ if (!empty($form_state['values']['i18n_mode']) && $form_state['values']['i18n_mode'] == I18N_MODE_ENTITY_TRANSLATION) {
+ $form_state['values']['entity_translation_taxonomy'] = TRUE;
+ }
+ $info = variable_get('entity_translation_taxonomy', array());
+ $info[$form_state['vocabulary']->machine_name] = !empty($form_state['values']['entity_translation_taxonomy']);
+ variable_set('entity_translation_taxonomy', $info);
+}
+
diff --git a/includes/translation.handler.taxonomy_term.inc b/includes/translation.handler.taxonomy_term.inc
index 0432bc0..03c7e40 100644
--- a/includes/translation.handler.taxonomy_term.inc
+++ b/includes/translation.handler.taxonomy_term.inc
@@ -21,7 +21,7 @@ class EntityTranslationTaxonomyTermHandler extends EntityTranslationDefaultHandl
public function getLanguage() {
if (isset($this->entity->vid) && module_exists('i18n_taxonomy')) {
$mode = i18n_taxonomy_vocabulary_mode($this->entity->vid);
- if ($mode == I18N_MODE_NONE) {
+ if ($mode == I18N_MODE_NONE || $mode == I18N_MODE_ENTITY_TRANSLATION) {
$translations = $this->getTranslations();
if (!empty($translations->original)) {
return $translations->original;