3 namespace Drupal\comment\Plugin\migrate\source\d7;
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
9 * Provides Drupal 7 comment entity translation source plugin.
12 * id = "d7_comment_entity_translation",
13 * source_module = "entity_translation"
16 class CommentEntityTranslation extends FieldableEntity {
21 public function query() {
22 $query = $this->select('entity_translation', 'et')
27 ->condition('et.entity_type', 'comment')
28 ->condition('et.source', '', '<>');
30 $query->innerJoin('comment', 'c', 'c.cid = et.entity_id');
31 $query->innerJoin('node', 'n', 'n.nid = c.nid');
33 $query->addField('n', 'type', 'node_type');
35 $query->orderBy('et.created');
43 public function prepareRow(Row $row) {
44 $cid = $row->getSourceProperty('entity_id');
45 $language = $row->getSourceProperty('language');
46 $node_type = $row->getSourceProperty('node_type');
47 $comment_type = 'comment_node_' . $node_type;
49 // Get Field API field values.
50 foreach ($this->getFields('comment', $comment_type) as $field_name => $field) {
51 // Ensure we're using the right language if the entity is translatable.
52 $field_language = $field['translatable'] ? $language : NULL;
53 $row->setSourceProperty($field_name, $this->getFieldValues('comment', $field_name, $cid, NULL, $field_language));
56 // If the comment subject was replaced by a real field using the Drupal 7
57 // Title module, use the field value instead of the comment subject.
58 if ($this->moduleExists('title')) {
59 $subject_field = $row->getSourceProperty('subject_field');
60 if (isset($subject_field[0]['value'])) {
61 $row->setSourceProperty('subject', $subject_field[0]['value']);
65 return parent::prepareRow($row);
71 public function fields() {
73 'entity_type' => $this->t('The entity type this translation relates to'),
74 'entity_id' => $this->t('The entity ID this translation relates to'),
75 'revision_id' => $this->t('The entity revision ID this translation relates to'),
76 'language' => $this->t('The target language for this translation.'),
77 'source' => $this->t('The source language from which this translation was created.'),
78 'uid' => $this->t('The author of this translation.'),
79 'status' => $this->t('Boolean indicating whether the translation is published (visible to non-administrators).'),
80 'translate' => $this->t('A boolean indicating whether this translation needs to be updated.'),
81 'created' => $this->t('The Unix timestamp when the translation was created.'),
82 'changed' => $this->t('The Unix timestamp when the translation was most recently saved.'),
83 'subject' => $this->t('The comment title.'),
90 public function getIds() {