Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / comment / src / Plugin / migrate / source / d6 / Comment.php
index 93f77a0e3f5ba3f90d1198c333d56864e697e7c8..5671d4f15665a95fab2b5c4be2341abfe763a6ea 100644 (file)
@@ -10,7 +10,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
  *
  * @MigrateSource(
  *   id = "d6_comment",
- *   source_provider = "comment"
+ *   source_module = "comment"
  * )
  */
 class Comment extends DrupalSqlBase {
@@ -21,10 +21,11 @@ class Comment extends DrupalSqlBase {
   public function query() {
     $query = $this->select('comments', 'c')
       ->fields('c', ['cid', 'pid', 'nid', 'uid', 'subject',
-        'comment', 'hostname', 'timestamp', 'status', 'thread', 'name',
-        'mail', 'homepage', 'format']);
+      'comment', 'hostname', 'timestamp', 'status', 'thread', 'name',
+      'mail', 'homepage', 'format',
+    ]);
     $query->innerJoin('node', 'n', 'c.nid = n.nid');
-    $query->fields('n', ['type']);
+    $query->fields('n', ['type', 'language']);
     $query->orderBy('c.timestamp');
     return $query;
   }
@@ -33,6 +34,20 @@ class Comment extends DrupalSqlBase {
    * {@inheritdoc}
    */
   public function prepareRow(Row $row) {
+    return parent::prepareRow($this->prepareComment($row));
+  }
+
+  /**
+   * This is a backward compatibility layer for the deprecated migrate source
+   * plugins d6_comment_variable and d6_comment_variable_per_comment_type.
+   *
+   * @param \Drupal\migrate\Row $row
+   *   The row from the source to process.
+   * @return \Drupal\migrate\Row
+   *   The row object.
+   * @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x.
+   */
+  protected function prepareComment(Row $row) {
     if ($this->variableGet('comment_subject_field_' . $row->getSourceProperty('type'), 1)) {
       // Comment subject visible.
       $row->setSourceProperty('field_name', 'comment');
@@ -42,10 +57,18 @@ class Comment extends DrupalSqlBase {
       $row->setSourceProperty('field_name', 'comment_no_subject');
       $row->setSourceProperty('comment_type', 'comment_no_subject');
     }
+
     // In D6, status=0 means published, while in D8 means the opposite.
     // See https://www.drupal.org/node/237636.
     $row->setSourceProperty('status', !$row->getSourceProperty('status'));
-    return parent::prepareRow($row);
+
+    // If node did not have a language, use site default language as a fallback.
+    if (!$row->getSourceProperty('language')) {
+      $language_default = $this->variableGet('language_default', NULL);
+      $language = $language_default ? $language_default->language : 'en';
+      $row->setSourceProperty('language', $language);
+    }
+    return $row;
   }
 
   /**
@@ -68,6 +91,7 @@ class Comment extends DrupalSqlBase {
       '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."),
       'type' => $this->t("The {node}.type to which this comment is a reply."),
+      'language' => $this->t("The {node}.language to which this comment is a reply. Site default language is used as a fallback if node does not have a language."),
     ];
   }