Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / comment / src / Plugin / migrate / source / d7 / Comment.php
index 4e3f3caa05ab562e537c35b8ac23d9681b53c9a6..73c2d8f4f7045c3a1191bd89b32e8191e9ccfd32 100644 (file)
@@ -36,8 +36,29 @@ class Comment extends FieldableEntity {
     $comment_type = 'comment_node_' . $node_type;
     $row->setSourceProperty('comment_type', 'comment_node_' . $node_type);
 
-    foreach (array_keys($this->getFields('comment', $comment_type)) as $field) {
-      $row->setSourceProperty($field, $this->getFieldValues('comment', $field, $cid));
+    // 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_comment_entity_translation
+    // migration.
+    $entity_translatable = $this->isEntityTranslatable('comment') && (int) $this->variableGet('language_content_type_' . $node_type, 0) === 4;
+    $source_language = $this->getEntityTranslationSourceLanguage('comment', $cid);
+    $language = $entity_translatable && $source_language ? $source_language : $row->getSourceProperty('language');
+
+    // Get Field API field values.
+    foreach ($this->getFields('comment', $comment_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('comment', $field_name, $cid, NULL, $field_language));
+    }
+
+    // If the comment subject was replaced by a real field using the Drupal 7
+    // Title module, use the field value instead of the comment subject.
+    if ($this->moduleExists('title')) {
+      $subject_field = $row->getSourceProperty('subject_field');
+      if (isset($subject_field[0]['value'])) {
+        $row->setSourceProperty('subject', $subject_field[0]['value']);
+      }
     }
 
     return parent::prepareRow($row);
@@ -63,6 +84,7 @@ class Comment extends FieldableEntity {
       'name' => $this->t("The comment author's name. Uses {users}.name if the user is logged in, otherwise uses the value typed into the comment form."),
       'mail' => $this->t("The comment author's email address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."),
       'homepage' => $this->t("The comment author's home page address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."),
+      'language' => $this->t('The comment language.'),
       'type' => $this->t("The {node}.type to which this comment is a reply."),
     ];
   }