Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / node / src / Plugin / migrate / source / d7 / Node.php
index 1a9037e7a00a4f0b6772815117cd6ad0bb96a800..931a2b94311c02f892cac258c7e9a8504b9d5966 100644 (file)
@@ -104,17 +104,40 @@ class Node extends FieldableEntity {
    * {@inheritdoc}
    */
   public function prepareRow(Row $row) {
+    $nid = $row->getSourceProperty('nid');
+    $vid = $row->getSourceProperty('vid');
+    $type = $row->getSourceProperty('type');
+
+    // If this entity was translated using Entity Translation, we need to get
+    // its source language to get the field values in the right language.
+    // The translations will be migrated by the d7_node_entity_translation
+    // migration.
+    $entity_translatable = $this->isEntityTranslatable('node') && (int) $this->variableGet('language_content_type_' . $type, 0) === 4;
+    $source_language = $this->getEntityTranslationSourceLanguage('node', $nid);
+    $language = $entity_translatable && $source_language ? $source_language : $row->getSourceProperty('language');
+
     // Get Field API field values.
-    foreach (array_keys($this->getFields('node', $row->getSourceProperty('type'))) as $field) {
-      $nid = $row->getSourceProperty('nid');
-      $vid = $row->getSourceProperty('vid');
-      $row->setSourceProperty($field, $this->getFieldValues('node', $field, $nid, $vid));
+    foreach ($this->getFields('node', $type) as $field_name => $field) {
+      // Ensure we're using the right language if the entity and the field are
+      // translatable.
+      $field_language = $entity_translatable && $field['translatable'] ? $language : NULL;
+      $row->setSourceProperty($field_name, $this->getFieldValues('node', $field_name, $nid, $vid, $field_language));
     }
 
     // Make sure we always have a translation set.
     if ($row->getSourceProperty('tnid') == 0) {
       $row->setSourceProperty('tnid', $row->getSourceProperty('nid'));
     }
+
+    // If the node title was replaced by a real field using the Drupal 7 Title
+    // module, use the field value instead of the node title.
+    if ($this->moduleExists('title')) {
+      $title_field = $row->getSourceProperty('title_field');
+      if (isset($title_field[0]['value'])) {
+        $row->setSourceProperty('title', $title_field[0]['value']);
+      }
+    }
+
     return parent::prepareRow($row);
   }