updated entity translation, seems to don't need patch anymore
This commit is contained in:
parent
c64b25b261
commit
ae7349e811
@ -1,8 +1,39 @@
|
||||
|
||||
Entity Translation 7.x-1.x, xxxx-xx-xx
|
||||
--------------------------------------
|
||||
#2444203 by Leksat, badrange, attiks: Show fallback information on the translation
|
||||
overview.
|
||||
#2189567 by stefanos.petrakis, jmuzz: Fixed problems enabling and disabling translation on
|
||||
a field with revisions enabled.
|
||||
#2798721 by gnucifer: Path scheme not initialized on delete translation confirmation form.
|
||||
#2215771 by colan, stefanos.petrakis: Fixed "Undefined index: translate in
|
||||
EntityTranslationDefaultHandler->entityForm()".
|
||||
#1829636 by bforchhammer, stefanos.petrakis: Fixed "All languages" suffix not
|
||||
working nicely with multi-value fields.
|
||||
#2746045 by fengtan: Converted dsm calls to watchdog calls for path scheme
|
||||
definition warnings.
|
||||
#2757601 by ctrnz, aks22: Fixed entity_translation_update_7009() assumes
|
||||
i18n_taxonomy is enabled.
|
||||
#1172104 by james.williams, daro.pl: Improved description of the language
|
||||
fallback option.
|
||||
#2734373 by plach, consulio: "entity_translation_update_7008" is broken when no
|
||||
term is translated.
|
||||
#2734301 by plach, sinasalek: Fixed Numeric value out of range: 1264 Out of
|
||||
range value for column 'i18n_mode'.
|
||||
#1661348 by plach, badrange, colan, candelas: Added "I18n Taxonomy" integration.
|
||||
|
||||
|
||||
Entity Translation 7.x-1.0-beta5, 2016-05-08
|
||||
--------------------------------------------
|
||||
#929402 by das-peter, bastnic, kristiaanvandeneynde, brockfanning, greenjuls,
|
||||
make77, steinmb: Added support for migrate module.
|
||||
#1291388 by Jax, poiu, plach: Added support for multilingual core search.
|
||||
#2339315 by loopduplicate, gnucifer, plopesc, james.williams: Fixed Source
|
||||
language prepopulated values should be also included in $form_state['field'].
|
||||
#2648062 by brunoric, cebasqueira, lucasr, mmchristoph: Fixed Fatal error: Call
|
||||
to a member function getFormLanguage() on a non-object.
|
||||
#S156840 by HelenaEksler, plach: Fixed XSS vulnerability in the translation
|
||||
form page title.
|
||||
#2444203 by Leksat, badrange, attiks: Show fallback information on the
|
||||
translation overview.
|
||||
#2458393 by catch, plach, douggreen: Fixed unindexed query in
|
||||
EntityTranslationDefaultHandler::loadMultiple().
|
||||
#2462909 by GeduR: Misspelling translation exists help in views handler
|
||||
@ -19,6 +50,7 @@ Entity Translation 7.x-1.x, xxxx-xx-xx
|
||||
i18n_taxonomy.
|
||||
#2415189 by catch: Translation deletion bypasses entity saving.
|
||||
|
||||
|
||||
Entity Translation 7.x-1.0-beta4, 2015-01-23
|
||||
--------------------------------------------
|
||||
#2396103 by plach: Fixed [DATA LOSS] Translations deleted.
|
||||
@ -296,7 +328,7 @@ Entity Translation 7.x-1.0-alpha1, 2011-09-07
|
||||
editing workflow.
|
||||
#1031370 by joostvdl | rfay: Fixed Translation publishing status is hidden under
|
||||
collapsed 'publishing options' fieldset (and is hidden by default).
|
||||
#1003876 by plach, good_man: (follow-up) Fixed original label translation.
|
||||
#1003876 by plach, good_man: (follow-up) Fixed original label translation.
|
||||
#1003876 by good_man, plach: Introduced support for translated entity labels.
|
||||
#936646 by good_man, fietserwin, plach, klonos: Fixed Undefined index access
|
||||
callback/arguments in entity_translation_menu().
|
||||
|
@ -13,8 +13,8 @@ function entity_translation_admin_form($form, $form_state) {
|
||||
|
||||
$form['locale_field_language_fallback'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable language fallback'),
|
||||
'#description' => t('When language fallback is enabled, if a translation is not available for the requested language an existing one will be displayed.'),
|
||||
'#title' => t('Allow language fallback'),
|
||||
'#description' => t('When language fallback is allowed, an alternative translation will be displayed if the requested language is not available. Other modules, such as <a href="https://www.drupal.org/project/language_hierarchy" target="_blank">Language Hierarchy</a>, are needed to manage which languages are used as fallbacks. Otherwise, existing translations will be chosen based on their <a href="!url">language weight</a>.', array('!url' => url('admin/config/regional/language'))),
|
||||
'#default_value' => variable_get('locale_field_language_fallback', TRUE),
|
||||
);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -410,6 +411,7 @@ function theme_entity_translation_overview_outdated($variables){
|
||||
function entity_translation_delete_confirm($form, $form_state, $entity_type, $entity, $langcode) {
|
||||
$handler = entity_translation_get_handler($entity_type, $entity);
|
||||
$handler->setFormLanguage($langcode);
|
||||
$handler->initPathScheme();
|
||||
$languages = language_list();
|
||||
|
||||
$form = array(
|
||||
@ -576,6 +578,7 @@ function entity_translation_translatable_batch($translatable, $field_name, $copy
|
||||
$query = new EntityFieldQuery();
|
||||
$count = $query
|
||||
->fieldCondition($field_name)
|
||||
->age(FIELD_LOAD_REVISION)
|
||||
->count()
|
||||
->execute();
|
||||
|
||||
@ -595,11 +598,16 @@ function entity_translation_translatable_batch($translatable, $field_name, $copy
|
||||
$result = $query
|
||||
->fieldCondition($field_name)
|
||||
->entityOrderBy('entity_id')
|
||||
->age(FIELD_LOAD_REVISION)
|
||||
->range($offset, $limit)
|
||||
->execute();
|
||||
|
||||
foreach ($result as $entity_type => $entities) {
|
||||
foreach (entity_load($entity_type, array_keys($entities)) as $entity) {
|
||||
foreach ($result as $entity_type => $revisions) {
|
||||
foreach ($revisions as $revision) {
|
||||
// $revision is a partial entity object that will be used as an array of
|
||||
// conditions.
|
||||
$conditions = (array) $revision;
|
||||
$entity = reset(entity_load($entity_type, FALSE, $conditions));
|
||||
$context['sandbox']['progress']++;
|
||||
$handler = entity_translation_get_handler($entity_type, $entity);
|
||||
$langcode = $handler->getLanguage();
|
||||
|
@ -11,6 +11,7 @@ files[] = includes/translation.handler.comment.inc
|
||||
files[] = includes/translation.handler.node.inc
|
||||
files[] = includes/translation.handler.taxonomy_term.inc
|
||||
files[] = includes/translation.handler.user.inc
|
||||
files[] = includes/translation.migrate.inc
|
||||
|
||||
files[] = tests/entity_translation.test
|
||||
|
||||
@ -22,9 +23,9 @@ files[] = views/entity_translation_handler_filter_language.inc
|
||||
files[] = views/entity_translation_handler_filter_translation_exists.inc
|
||||
files[] = views/entity_translation_handler_field_field.inc
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-08-16
|
||||
version = "7.x-1.0-beta4+10-dev"
|
||||
; Information added by Drupal.org packaging script on 2016-09-28
|
||||
version = "7.x-1.0-beta5+15-dev"
|
||||
core = "7.x"
|
||||
project = "entity_translation"
|
||||
datestamp = "1439732040"
|
||||
datestamp = "1475057941"
|
||||
|
||||
|
@ -446,3 +446,41 @@ 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();
|
||||
|
||||
if ($vids) {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure "i18n_mode" is correctly set for vocabularies having entity
|
||||
* translation enabled.
|
||||
*/
|
||||
function entity_translation_update_7009() {
|
||||
$info = array_filter(variable_get('entity_translation_taxonomy', array()));
|
||||
if ($info && module_exists('i18n_taxonomy')) {
|
||||
$query = "UPDATE {taxonomy_vocabulary} SET i18n_mode = :et_mode WHERE machine_name IN (:names)";
|
||||
$names = array_keys(array_filter($info));
|
||||
db_query($query, array(':et_mode' => 32768, ':names' => $names));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Implements a Migrate destination handler to automatically add translations
|
||||
* to entities with translatable fields.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_migrate_api().
|
||||
*/
|
||||
function entity_translation_migrate_api() {
|
||||
$api = array(
|
||||
'api' => 2,
|
||||
'destination handlers' => array('MigrateTranslationEntityHandler'),
|
||||
);
|
||||
return $api;
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
@ -43,14 +43,15 @@ 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';
|
||||
@ -249,3 +250,24 @@ function entity_translation_query_comment_filter_alter(QueryAlterableInterface $
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_node_update_index().
|
||||
*
|
||||
* Add translated node content to search index.
|
||||
*/
|
||||
function entity_translation_node_update_index($node) {
|
||||
$text = '';
|
||||
$langcodes = array_keys(language_list());
|
||||
$translations = entity_translation_get_handler('node', $node)->getTranslations();
|
||||
foreach ($langcodes as $langcode) {
|
||||
// Skip the default language (already indexed by search.module).
|
||||
if ($GLOBALS[LANGUAGE_TYPE_CONTENT]->language != $langcode && isset($translations->data[$langcode])) {
|
||||
// Render the node in each language.
|
||||
node_build_content($node, 'search_index', $langcode);
|
||||
$rendered = drupal_render($node->content);
|
||||
$text .= '<h1>' . check_plain($node->title) . '</h1>' . $rendered;
|
||||
}
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* The taxonomy specific translation functions and hook implementations.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns whether the given taxonomy vocabulary has support for translations.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if translation is enabled, FALSE otherwise.
|
||||
*/
|
||||
function entity_translation_taxonomy_term_enabled_vocabulary($vocabulary_name) {
|
||||
$info = variable_get('entity_translation_taxonomy', array());
|
||||
return !empty($info[$vocabulary_name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Taxonomy-term-specific menu alterations.
|
||||
*/
|
||||
function entity_translation_taxonomy_term_menu_alter(&$items, $backup) {
|
||||
if (isset($backup['taxonomy_term'])) {
|
||||
$item = $backup['taxonomy_term'];
|
||||
// Preserve the menu router item defined by other modules.
|
||||
$callback['page callback'] = $item['page callback'];
|
||||
$callback['file'] = $item['file'];
|
||||
$callback['module'] = $item['module'];
|
||||
$access_arguments = array_merge(array(2, $item['access callback']), $item['access arguments']);
|
||||
$page_arguments = array_merge(array('taxonomy_term', 2, $callback), $item['page arguments']);
|
||||
}
|
||||
else {
|
||||
$access_arguments = array(2);
|
||||
$page_arguments = array('taxonomy_term', 2);
|
||||
}
|
||||
|
||||
$items['taxonomy/term/%taxonomy_term/translate']['page callback'] = 'entity_translation_overview';
|
||||
$items['taxonomy/term/%taxonomy_term/translate']['page arguments'] = $page_arguments;
|
||||
$items['taxonomy/term/%taxonomy_term/translate']['access arguments'] = $access_arguments;
|
||||
$items['taxonomy/term/%taxonomy_term/translate']['access callback'] = 'entity_translation_taxonomy_term_tab_access';
|
||||
$items['taxonomy/term/%taxonomy_term/translate']['file'] = 'entity_translation.admin.inc';
|
||||
$items['taxonomy/term/%taxonomy_term/translate']['module'] = 'entity_translation';
|
||||
}
|
||||
|
||||
/**
|
||||
* Taxonomy term specific access callback.
|
||||
*/
|
||||
function entity_translation_taxonomy_term_tab_access() {
|
||||
$args = func_get_args();
|
||||
$term = array_shift($args);
|
||||
if (entity_translation_enabled('taxonomy_term', $term)) {
|
||||
return entity_translation_tab_access('taxonomy_term', $term);
|
||||
}
|
||||
else {
|
||||
$function = array_shift($args);
|
||||
return $function ? call_user_func_array($function, $args) : FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter()
|
||||
*/
|
||||
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 <a href="!url">Entity translation</a> 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' => '<label>' . t('Translation') . '</label>',
|
||||
'#default_value' => entity_translation_enabled('taxonomy_term', $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);
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ dependencies[] = i18n
|
||||
dependencies[] = i18n_menu
|
||||
files[] = entity_translation_i18n_menu.test
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-08-16
|
||||
version = "7.x-1.0-beta4+10-dev"
|
||||
; Information added by Drupal.org packaging script on 2016-09-28
|
||||
version = "7.x-1.0-beta5+15-dev"
|
||||
core = "7.x"
|
||||
project = "entity_translation"
|
||||
datestamp = "1439732040"
|
||||
datestamp = "1475057941"
|
||||
|
||||
|
@ -4,9 +4,9 @@ package = Multilingual - Entity Translation
|
||||
core = 7.x
|
||||
dependencies[] = entity_translation
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-08-16
|
||||
version = "7.x-1.0-beta4+10-dev"
|
||||
; Information added by Drupal.org packaging script on 2016-09-28
|
||||
version = "7.x-1.0-beta5+15-dev"
|
||||
core = "7.x"
|
||||
project = "entity_translation"
|
||||
datestamp = "1439732040"
|
||||
datestamp = "1475057941"
|
||||
|
||||
|
@ -1281,7 +1281,7 @@ class EntityTranslationDefaultHandler implements EntityTranslationHandlerInterfa
|
||||
'#disabled' => !$enabled,
|
||||
);
|
||||
|
||||
$translate = !$new_translation && $translations->data[$form_langcode]['translate'];
|
||||
$translate = !$new_translation && !empty($translations->data[$form_langcode]['translate']);
|
||||
if (!$translate) {
|
||||
$form['translation']['retranslate'] = array(
|
||||
'#type' => 'checkbox',
|
||||
@ -1612,9 +1612,12 @@ class EntityTranslationDefaultHandler implements EntityTranslationHandlerInterfa
|
||||
|
||||
/**
|
||||
* Returns the title to be used for the entity form page.
|
||||
*
|
||||
* This may contain HTML markup and thus needs to be sanitized, since it will
|
||||
* be used as page title as-is.
|
||||
*/
|
||||
protected function entityFormTitle() {
|
||||
return $this->getLabel();
|
||||
return check_plain($this->getLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,7 +21,9 @@ 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) {
|
||||
// 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)) {
|
||||
return $translations->original;
|
||||
@ -48,4 +50,5 @@ class EntityTranslationTaxonomyTermHandler extends EntityTranslationDefaultHandl
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* MigrateTranslationEntityHandler class for entity_translation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Destination handler implementing translatable fields.
|
||||
*/
|
||||
class MigrateTranslationEntityHandler extends MigrateDestinationHandler {
|
||||
/**
|
||||
* Registers all entites as handled by this class.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->registerTypes(array('entity'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles Entity Translations.
|
||||
*
|
||||
* @param stdClass $entity
|
||||
* @param stdClass $sourceRow
|
||||
*/
|
||||
public function prepare($entity, stdClass $row) {
|
||||
$migration = Migration::currentMigration();
|
||||
$entity_type = $migration->getDestination()->getEntityType();
|
||||
|
||||
// Only continue if the entity type + bundle combination is enabled for
|
||||
// entity_translation.
|
||||
if (entity_translation_enabled($entity_type, $entity)) {
|
||||
// Get the entity_translation handler and load any existing translations.
|
||||
$handler = entity_translation_get_handler($entity_type, $entity);
|
||||
$handler->loadTranslations();
|
||||
$original_language = $handler->getLanguage();
|
||||
|
||||
// Get the bundle of the entity.
|
||||
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
|
||||
|
||||
// We need to get all of the possible translations to create. So we look
|
||||
// for any translatable fields.
|
||||
$translatable_fields = array();
|
||||
foreach (field_info_instances($entity_type, $bundle) as $instance) {
|
||||
$field_name = $instance['field_name'];
|
||||
$field = field_info_field($field_name);
|
||||
|
||||
if ($field['translatable']) {
|
||||
$translatable_fields[] = $field_name;
|
||||
}
|
||||
}
|
||||
|
||||
// In those fields we look for translated values to build out an array
|
||||
// of languages we need to set translations for.
|
||||
$translate_languages = array();
|
||||
foreach ($translatable_fields as $translatable_field) {
|
||||
if (!empty($entity->{$translatable_field})) {
|
||||
$field_languages = array_keys($entity->{$translatable_field});
|
||||
foreach ($field_languages as $field_language) {
|
||||
$translate_languages[$field_language] = $field_language;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the LANGUAGE_NONE results.
|
||||
unset($translate_languages[LANGUAGE_NONE]);
|
||||
|
||||
// Remove the original language.
|
||||
unset($translate_languages[$original_language]);
|
||||
|
||||
// Anything we're left with is a translation that should be set.
|
||||
foreach ($translate_languages as $translate_language) {
|
||||
if (!isset($entity->translations->data[$translate_language])) {
|
||||
// Add the new translation and store it.
|
||||
$handler->setTranslation(array(
|
||||
'translate' => 0,
|
||||
'status' => 1,
|
||||
'language' => $translate_language,
|
||||
'source' => $original_language,
|
||||
'uid' => (empty($entity->uid)) ? 0 : $entity->uid,
|
||||
'changed' => (empty($entity->changed)) ? REQUEST_TIME : $entity->changed,
|
||||
'created' => (empty($entity->created)) ? REQUEST_TIME : $entity->created,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -64,6 +64,7 @@ class EntityTranslationTestCase extends DrupalWebTestCase {
|
||||
$this->admin_user = $this->drupalCreateUser(array_merge(array(
|
||||
'bypass node access',
|
||||
'administer nodes',
|
||||
'administer fields',
|
||||
'administer languages',
|
||||
'administer content types',
|
||||
'administer blocks',
|
||||
|
@ -6,9 +6,9 @@ hidden = TRUE
|
||||
dependencies[] = entity_translation
|
||||
files[] = entity_translation_test.module
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-08-16
|
||||
version = "7.x-1.0-beta4+10-dev"
|
||||
; Information added by Drupal.org packaging script on 2016-09-28
|
||||
version = "7.x-1.0-beta5+15-dev"
|
||||
core = "7.x"
|
||||
project = "entity_translation"
|
||||
datestamp = "1439732040"
|
||||
datestamp = "1475057941"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user