summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Ryan2011-02-06 22:46:42 (GMT)
committer Mike Ryan2011-02-06 22:46:42 (GMT)
commit61428d744107291de6b9a723a011b33f011ebb99 (patch)
tree50996c5257cd45157da528db6734e383f16e4bc3
parenta1697d07fd6575fbad829c4b789d40f8042cde1e (diff)
#914440 by das-peter: Enhance multilingual support
-rw-r--r--CHANGELOG.txt1
-rw-r--r--plugins/destinations/fields.inc46
-rw-r--r--plugins/destinations/node.inc10
3 files changed, 40 insertions, 17 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 71c1b63..1029212 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -13,6 +13,7 @@ Features and enhancements
Let a node migration set node_revisions.uid. That's the 'last edited by' user
Bug fixes
+- #914440 - Enhance multilingual support.
- #1014648 - Defaulting of file field subfields.
- #1037872 - Make sure is_new is off for previously migrated content.
- #919706 - Fix drush migrate-descriptions command.
diff --git a/plugins/destinations/fields.inc b/plugins/destinations/fields.inc
index 5ad3792..c3af4e7 100644
--- a/plugins/destinations/fields.inc
+++ b/plugins/destinations/fields.inc
@@ -50,6 +50,29 @@ class MigrateFieldsEntityHandler extends MigrateDestinationHandler {
abstract class MigrateFieldHandler extends MigrateHandler {
// abstract function arguments(...)
abstract public function prepare(stdClass $entity, array $field_info, array $instance, array $values);
+
+ /**
+ * Determine the language of the field
+ *
+ * @param $entity
+ * @param $field_info
+ * @param $arguments
+ * @return string language code
+ */
+ function getFieldLanguage(stdClass $entity, $field_info, array $arguments) {
+ $migration = Migration::currentMigration();
+ switch (TRUE) {
+ case !field_is_translatable($migration->getDestination()->getEntityType(), $field_info):
+ return LANGUAGE_NONE;
+ case isset($arguments['language']):
+ return $arguments['language'];
+ case $entity->language != LANGUAGE_NONE:
+ return $entity->language;
+ break;
+ default:
+ return $migration->getDestination()->getLanguage();
+ }
+ }
}
class MigrateTextFieldHandler extends MigrateFieldHandler {
@@ -82,8 +105,8 @@ class MigrateTextFieldHandler extends MigrateFieldHandler {
$migration = Migration::currentMigration();
$destination = $migration->getDestination();
- $language = isset($arguments['language']) ?
- $arguments['language'] : $destination->getLanguage();
+ $language = $this->getFieldLanguage($entity, $field_info, $arguments);
+
// Setup the standard Field API array for saving.
$delta = 0;
@@ -113,9 +136,8 @@ class MigrateValueFieldHandler extends MigrateFieldHandler {
public function prepare(stdClass $entity, array $field_info, array $instance, array $values) {
$migration = Migration::currentMigration();
- $language = isset($arguments['language']) ?
- $arguments['language'] : $migration->getDestination()->getLanguage();
-
+ $arguments = (isset($values['arguments']))? $values['arguments']: array();
+ $language = $this->getFieldLanguage($entity, $field_info, $arguments);
// Setup the standard Field API array for saving.
$delta = 0;
foreach ($values as $value) {
@@ -170,8 +192,7 @@ class MigrateTaxonomyTermReferenceFieldHandler extends MigrateFieldHandler {
else {
$tids = array();
}
- $language = isset($arguments['language']) ?
- $arguments['language'] : $migration->getDestination()->getLanguage();
+ $language = $this->getFieldLanguage($entity, $field_info, $arguments);
$result = array();
$i = 0;
foreach ($tids as $tid) {
@@ -199,8 +220,8 @@ class MigrateFileFieldHandler extends MigrateFieldHandler {
unset($values['arguments']);
$migration = Migration::currentMigration();
- $language = isset($arguments['language']) ? $arguments['language'] :
- $migration->getDestination()->getLanguage();
+ $language = $this->getFieldLanguage($entity, $field_info, $arguments);
+
$return = array();
if (empty($arguments['separator'])) {
@@ -410,8 +431,8 @@ class MigrateNodeReferenceFieldHandler extends MigrateFieldHandler {
else {
$arguments = array();
}
- $language = isset($arguments['language']) ? $arguments['language'] :
- $migration->getDestination()->getLanguage();
+
+ $language = $this->getFieldLanguage($entity, $field_info, $arguments);
// Setup the standard Field API array for saving.
$delta = 0;
@@ -441,8 +462,7 @@ class MigrateUserReferenceFieldHandler extends MigrateFieldHandler {
else {
$arguments = array();
}
- $language = isset($arguments['language']) ?
- $arguments['language'] : $migration->getDestination()->getLanguage();
+ $language = $this->getFieldLanguage($entity, $field_info, $arguments);
// Setup the standard Field API array for saving.
$delta = 0;
diff --git a/plugins/destinations/node.inc b/plugins/destinations/node.inc
index 0c362d1..811f5a2 100644
--- a/plugins/destinations/node.inc
+++ b/plugins/destinations/node.inc
@@ -122,12 +122,14 @@ class MigrateDestinationNode extends MigrateDestinationEntity {
else {
$node->nid = $row->migrate_map_destid1;
}
- // Get the existing vid, so updates don't generate notices
- $node->vid = db_select('node', 'n')
- ->fields('n', array('vid'))
+ // Get the existing vid, tnid so updates don't generate notices
+ $values = db_select('node', 'n')
+ ->fields('n', array('vid', 'tnid'))
->condition('nid', $node->nid)
->execute()
- ->fetchField();
+ ->fetchAssoc();
+ $node->vid = $values['vid'];
+ $node->tnid = $values['tnid'];
}
if ($migration->getSystemOfRecord() == Migration::DESTINATION) {
if (!isset($node->nid)) {