|
@@ -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', 32768);
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 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',
|
|
|
),
|
|
|
),
|
|
|
);
|
|
@@ -290,7 +299,7 @@ function _entity_translation_validate_path_schemes(&$schemes, $entity_type_label
|
|
|
if (empty($scheme['path wildcard'])) {
|
|
|
if ($warnings) {
|
|
|
$t_args = array('%scheme' => $delta, '%entity_type' => $entity_type_label);
|
|
|
- drupal_set_message(t('Entity Translation path scheme %scheme for entities of type %entity_type does not declare a path wildcard.', $t_args), 'warning');
|
|
|
+ watchdog('entity_translation', 'Entity Translation path scheme %scheme for entities of type %entity_type does not declare a path wildcard.', $t_args);
|
|
|
}
|
|
|
unset($schemes[$delta]);
|
|
|
continue;
|
|
@@ -504,12 +513,13 @@ function entity_translation_menu_alter(&$items) {
|
|
|
}
|
|
|
|
|
|
if ($translate_ui_attached == FALSE) {
|
|
|
- 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');
|
|
|
+ watchdog('entity_translation', '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']));
|
|
|
}
|
|
|
|
|
|
- // 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();
|
|
@@ -1274,10 +1277,14 @@ function entity_translation_field_attach_form($entity_type, $entity, &$form, &$f
|
|
|
function entity_translation_prepare_element($element, &$form_state) {
|
|
|
static $drupal_static_fast;
|
|
|
if (!isset($drupal_static_fast)) {
|
|
|
- $drupal_static_fast['source_forms'] = &drupal_static(__FUNCTION__, array());
|
|
|
+ $drupal_static_fast = &drupal_static(__FUNCTION__, array(
|
|
|
+ 'source_forms' => array(),
|
|
|
+ 'source_form_states' => array(),
|
|
|
+ ));
|
|
|
}
|
|
|
|
|
|
$source_forms = &$drupal_static_fast['source_forms'];
|
|
|
+ $source_form_states = &$drupal_static_fast['source_form_states'];
|
|
|
$form = $form_state['complete form'];
|
|
|
$build_id = $form['#build_id'];
|
|
|
$source = $element['#source'];
|
|
@@ -1294,9 +1301,11 @@ function entity_translation_prepare_element($element, &$form_state) {
|
|
|
$source_form_state = $form_state;
|
|
|
field_attach_form($entity_type, $element['#entity'], $source_form, $source_form_state, $source);
|
|
|
$source_forms[$build_id][$source][$entity_type][$id] = &$source_form;
|
|
|
+ $source_form_states[$build_id][$source][$entity_type][$id] = &$source_form_state;
|
|
|
}
|
|
|
|
|
|
$source_form = &$source_forms[$build_id][$source][$entity_type][$id];
|
|
|
+ $source_form_state = $source_form_states[$build_id][$source][$entity_type][$id];
|
|
|
$langcode = $element['#language'];
|
|
|
$field_name = $element['#field_name'];
|
|
|
|
|
@@ -1307,12 +1316,42 @@ function entity_translation_prepare_element($element, &$form_state) {
|
|
|
if (isset($source_form[$field_name][$source])) {
|
|
|
$element[$langcode] = $source_form[$field_name][$source];
|
|
|
entity_translation_form_element_language_replace($element, $source, $langcode);
|
|
|
+ entity_translation_form_element_state_replace($element, $source_form[$field_name], $field_name, $source_form_state, $form_state);
|
|
|
unset($element[$element['#previous']]);
|
|
|
}
|
|
|
|
|
|
return $element;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Helper function. Sets the right values in $form_state['field'] when using
|
|
|
+ * source language values as defaults.
|
|
|
+ */
|
|
|
+function entity_translation_form_element_state_replace($element, $source_element, $field_name, $source_form_state, &$form_state) {
|
|
|
+ if (isset($source_element['#language'])) {
|
|
|
+ $source = $source_element['#language'];
|
|
|
+
|
|
|
+ // Iterate through the form structure recursively.
|
|
|
+ foreach (element_children($element) as $key) {
|
|
|
+ if (isset($source_element[$key])) {
|
|
|
+ entity_translation_form_element_state_replace($element[$key], $source_element[$key], $key, $source_form_state, $form_state);
|
|
|
+ }
|
|
|
+ elseif (isset($source_element[$source])) {
|
|
|
+ entity_translation_form_element_state_replace($element[$key], $source_element[$source], $key, $source_form_state, $form_state);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($source_element[$source]['#field_parents'])) {
|
|
|
+ $source_parents = $source_element[$source]['#field_parents'];
|
|
|
+ $langcode = $element['#language'];
|
|
|
+ $parents = $element[$langcode]['#field_parents'];
|
|
|
+ $source_state = field_form_get_state($source_parents, $field_name, $source, $source_form_state);
|
|
|
+ drupal_alter('entity_translation_source_field_state', $source_state);
|
|
|
+ field_form_set_state($parents, $field_name, $langcode, $form_state, $source_state);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Helper function. Recursively replaces the source language with the given one.
|
|
|
*/
|
|
@@ -1425,6 +1464,10 @@ function _entity_translation_element_title_append(&$element, $suffix) {
|
|
|
if (isset($element['#type']) && isset($fapi_title_elements[$element['#type']]) && isset($element['#title'])) {
|
|
|
$element['#title'] .= $suffix;
|
|
|
}
|
|
|
+ // If this is a multi-valued field, apply the suffix to the container.
|
|
|
+ elseif (isset($element['#title']) && isset($element['#cardinality']) && $element['#cardinality'] != 1) {
|
|
|
+ $element['#title'] .= $suffix;
|
|
|
+ }
|
|
|
// If the current element does not have a (valid) title, try child elements.
|
|
|
elseif ($children = element_children($element)) {
|
|
|
foreach ($children as $delta) {
|
|
@@ -1799,6 +1842,9 @@ function entity_translation_settings($entity_type, $bundle) {
|
|
|
*/
|
|
|
function entity_translation_language($entity_type, $entity) {
|
|
|
$handler = entity_translation_get_handler($entity_type, $entity);
|
|
|
+ if (empty($handler)) {
|
|
|
+ return LANGUAGE_NONE;
|
|
|
+ }
|
|
|
$langcode = $handler->getFormLanguage();
|
|
|
return !empty($langcode) ? $langcode : $handler->getLanguage();
|
|
|
}
|