updated entity translation, seems to don't need patch anymore
This commit is contained in:
@@ -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,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user