You are here

public function CommentEntityTranslation::prepareRow in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/comment/src/Plugin/migrate/source/d7/CommentEntityTranslation.php \Drupal\comment\Plugin\migrate\source\d7\CommentEntityTranslation::prepareRow()

Adds additional data to the row.

Parameters

\Drupal\migrate\Row $row: The row object.

Return value

bool FALSE if this row needs to be skipped.

Overrides SourcePluginBase::prepareRow

File

core/modules/comment/src/Plugin/migrate/source/d7/CommentEntityTranslation.php, line 49

Class

CommentEntityTranslation
Drupal 7 comment entity translation source plugin.

Namespace

Drupal\comment\Plugin\migrate\source\d7

Code

public function prepareRow(Row $row) {
  $cid = $row
    ->getSourceProperty('entity_id');
  $language = $row
    ->getSourceProperty('language');
  $node_type = $row
    ->getSourceProperty('node_type');
  $comment_type = 'comment_node_' . $node_type;

  // 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 is translatable.
    $field_language = $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);
}