function Comment::prepareRow

Same name in this branch
  1. 9 core/modules/comment/src/Plugin/migrate/source/d6/Comment.php \Drupal\comment\Plugin\migrate\source\d6\Comment::prepareRow()
Same name in other branches
  1. 8.9.x core/modules/comment/src/Plugin/migrate/source/d6/Comment.php \Drupal\comment\Plugin\migrate\source\d6\Comment::prepareRow()
  2. 8.9.x core/modules/comment/src/Plugin/migrate/source/d7/Comment.php \Drupal\comment\Plugin\migrate\source\d7\Comment::prepareRow()
  3. 10 core/modules/comment/src/Plugin/migrate/source/d6/Comment.php \Drupal\comment\Plugin\migrate\source\d6\Comment::prepareRow()
  4. 10 core/modules/comment/src/Plugin/migrate/source/d7/Comment.php \Drupal\comment\Plugin\migrate\source\d7\Comment::prepareRow()
  5. 11.x core/modules/comment/src/Plugin/migrate/source/d6/Comment.php \Drupal\comment\Plugin\migrate\source\d6\Comment::prepareRow()
  6. 11.x core/modules/comment/src/Plugin/migrate/source/d7/Comment.php \Drupal\comment\Plugin\migrate\source\d7\Comment::prepareRow()

Overrides SourcePluginBase::prepareRow

File

core/modules/comment/src/Plugin/migrate/source/d7/Comment.php, line 39

Class

Comment
Drupal 7 comment source from database.

Namespace

Drupal\comment\Plugin\migrate\source\d7

Code

public function prepareRow(Row $row) {
    $cid = $row->getSourceProperty('cid');
    $node_type = $row->getSourceProperty('node_type');
    $comment_type = 'comment_node_' . $node_type;
    $row->setSourceProperty('comment_type', 'comment_node_' . $node_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_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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.