summaryrefslogtreecommitdiffstats
path: root/core/modules/migrate_drupal
diff options
context:
space:
mode:
authorGábor Hojtsy2018-07-27 19:41:20 (GMT)
committerGábor Hojtsy2018-07-27 19:41:47 (GMT)
commitddb1c342b4aa3b33a08870f5ebaff02674f60b21 (patch)
treed7208ab2ad9a82dc391b7d8bc0c6d927b2bdfd59 /core/modules/migrate_drupal
parentbc0e16cb81b5a7c6c923902a60296cda9d2b9635 (diff)
Issue #2975666 by maxocub, benjifisher, masipila, jcnventura, jigarius, phenaproxima, catch, quietone: Migrate Drupal 7 node entity translations data to Drupal 8
(cherry picked from commit 0f336ae86d026d4c0dd6eaeca00344b4d4201dac)
Diffstat (limited to 'core/modules/migrate_drupal')
-rw-r--r--core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldableEntity.php68
-rw-r--r--core/modules/migrate_drupal/tests/fixtures/drupal7.php91
2 files changed, 149 insertions, 10 deletions
diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldableEntity.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldableEntity.php
index 9527513..fe0fe48 100644
--- a/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldableEntity.php
+++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldableEntity.php
@@ -22,13 +22,18 @@ abstract class FieldableEntity extends DrupalSqlBase {
* The field instances, keyed by field name.
*/
protected function getFields($entity_type, $bundle = NULL) {
- return $this->select('field_config_instance', 'fci')
+ $query = $this->select('field_config_instance', 'fci')
->fields('fci')
- ->condition('entity_type', $entity_type)
- ->condition('bundle', isset($bundle) ? $bundle : $entity_type)
- ->condition('deleted', 0)
- ->execute()
- ->fetchAllAssoc('field_name');
+ ->condition('fci.entity_type', $entity_type)
+ ->condition('fci.bundle', isset($bundle) ? $bundle : $entity_type)
+ ->condition('fci.deleted', 0);
+
+ // Join the 'field_config' table and add the 'translatable' setting to the
+ // query.
+ $query->leftJoin('field_config', 'fc', 'fci.field_id = fc.id');
+ $query->addField('fc', 'translatable');
+
+ return $query->execute()->fetchAllAssoc('field_name');
}
/**
@@ -42,13 +47,13 @@ abstract class FieldableEntity extends DrupalSqlBase {
* The entity ID.
* @param int|null $revision_id
* (optional) The entity revision ID.
+ * @param string $language
+ * (optional) The field language.
*
* @return array
* The raw field values, keyed by delta.
- *
- * @todo Support multilingual field values.
*/
- protected function getFieldValues($entity_type, $field, $entity_id, $revision_id = NULL) {
+ protected function getFieldValues($entity_type, $field, $entity_id, $revision_id = NULL, $language = NULL) {
$table = (isset($revision_id) ? 'field_revision_' : 'field_data_') . $field;
$query = $this->select($table, 't')
->fields('t')
@@ -58,6 +63,11 @@ abstract class FieldableEntity extends DrupalSqlBase {
if (isset($revision_id)) {
$query->condition('revision_id', $revision_id);
}
+ // Add 'language' as a query condition if it has been defined by Entity
+ // Translation.
+ if ($language) {
+ $query->condition('language', $language);
+ }
$values = [];
foreach ($query->execute() as $row) {
foreach ($row as $key => $value) {
@@ -71,4 +81,44 @@ abstract class FieldableEntity extends DrupalSqlBase {
return $values;
}
+ /**
+ * Checks if an entity type uses Entity Translation.
+ *
+ * @param string $entity_type
+ * The entity type.
+ *
+ * @return bool
+ * Whether the entity type uses entity translation.
+ */
+ protected function isEntityTranslatable($entity_type) {
+ return in_array($entity_type, $this->variableGet('entity_translation_entity_types', []), TRUE);
+ }
+
+ /**
+ * Gets an entity source language from the 'entity_translation' table.
+ *
+ * @param string $entity_type
+ * The entity type.
+ * @param int $entity_id
+ * The entity ID.
+ *
+ * @return string|bool
+ * The entity source language or FALSE if no source language was found.
+ */
+ protected function getEntityTranslationSourceLanguage($entity_type, $entity_id) {
+ try {
+ return $this->select('entity_translation', 'et')
+ ->fields('et', ['language'])
+ ->condition('entity_type', $entity_type)
+ ->condition('entity_id', $entity_id)
+ ->condition('source', '')
+ ->execute()
+ ->fetchField();
+ }
+ // The table might not exist.
+ catch (\Exception $e) {
+ return FALSE;
+ }
+ }
+
}
diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
index 5311407..c2a7b68 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
@@ -3108,6 +3108,42 @@ $connection->insert('entity_translation')
'changed' => '1421727536',
))
->values(array(
+ 'entity_type' => 'node',
+ 'entity_id' => '1',
+ 'revision_id' => '1',
+ 'language' => 'en',
+ 'source' => '',
+ 'uid' => '1',
+ 'status' => '1',
+ 'translate' => '0',
+ 'created' => '1529615790',
+ 'changed' => '1529615790',
+))
+->values(array(
+ 'entity_type' => 'node',
+ 'entity_id' => '1',
+ 'revision_id' => '1',
+ 'language' => 'fr',
+ 'source' => 'en',
+ 'uid' => '1',
+ 'status' => '1',
+ 'translate' => '0',
+ 'created' => '1529615802',
+ 'changed' => '1529615802',
+))
+->values(array(
+ 'entity_type' => 'node',
+ 'entity_id' => '1',
+ 'revision_id' => '1',
+ 'language' => 'is',
+ 'source' => 'en',
+ 'uid' => '1',
+ 'status' => '1',
+ 'translate' => '0',
+ 'created' => '1529615813',
+ 'changed' => '1529615813',
+))
+->values(array(
'entity_type' => 'user',
'entity_id' => '2',
'revision_id' => '2',
@@ -5810,6 +5846,26 @@ $connection->insert('field_data_field_integer')
'field_integer_value' => '5',
))
->values(array(
+ 'entity_type' => 'node',
+ 'bundle' => 'test_content_type',
+ 'deleted' => '0',
+ 'entity_id' => '1',
+ 'revision_id' => '1',
+ 'language' => 'fr',
+ 'delta' => '0',
+ 'field_integer_value' => '6',
+))
+->values(array(
+ 'entity_type' => 'node',
+ 'bundle' => 'test_content_type',
+ 'deleted' => '0',
+ 'entity_id' => '1',
+ 'revision_id' => '1',
+ 'language' => 'is',
+ 'delta' => '0',
+ 'field_integer_value' => '7',
+))
+->values(array(
'entity_type' => 'user',
'bundle' => 'user',
'deleted' => '0',
@@ -9563,6 +9619,26 @@ $connection->insert('field_revision_field_integer')
'field_integer_value' => '5',
))
->values(array(
+ 'entity_type' => 'node',
+ 'bundle' => 'test_content_type',
+ 'deleted' => '0',
+ 'entity_id' => '1',
+ 'revision_id' => '1',
+ 'language' => 'fr',
+ 'delta' => '0',
+ 'field_integer_value' => '6',
+))
+->values(array(
+ 'entity_type' => 'node',
+ 'bundle' => 'test_content_type',
+ 'deleted' => '0',
+ 'entity_id' => '1',
+ 'revision_id' => '1',
+ 'language' => 'is',
+ 'delta' => '0',
+ 'field_integer_value' => '7',
+))
+->values(array(
'entity_type' => 'user',
'bundle' => 'user',
'deleted' => '0',
@@ -12975,6 +13051,19 @@ $connection->insert('languages')
'javascript' => '',
))
->values(array(
+ 'language' => 'fr',
+ 'name' => 'French',
+ 'native' => 'Français',
+ 'direction' => '0',
+ 'enabled' => '1',
+ 'plurals' => '0',
+ 'formula' => '',
+ 'domain' => 'fr.drupal.org',
+ 'prefix' => 'fr',
+ 'weight' => '0',
+ 'javascript' => '',
+))
+->values(array(
'language' => 'is',
'name' => 'Icelandic',
'native' => 'Íslenska',
@@ -48305,7 +48394,7 @@ $connection->insert('variable')
))
->values(array(
'name' => 'language_count',
- 'value' => 'i:2;',
+ 'value' => 'i:3;',
))
->values(array(
'name' => 'language_default',