3 namespace Drupal\comment\Plugin\migrate\source\d7;
5 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
6 use Drupal\migrate\Row;
7 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
10 * Drupal 7 comment type source from database.
13 * id = "d7_comment_type",
14 * source_provider = "comment"
17 class CommentType extends DrupalSqlBase {
20 * A map of D7 node types to their labels.
24 protected $nodeTypes = [];
29 public function query() {
30 return $this->select('field_config_instance', 'fci')
32 ->fields('fci', ['bundle'])
33 ->condition('fci.entity_type', 'comment');
39 protected function initializeIterator() {
40 $this->nodeTypes = $this->select('node_type', 'nt')
41 ->fields('nt', ['type', 'name'])
45 return parent::initializeIterator();
51 public function prepareRow(Row $row) {
52 $node_type = substr($row->getSourceProperty('bundle'), 13);
53 $row->setSourceProperty('node_type', $node_type);
55 $row->setSourceProperty('default_mode', $this->variableGet("comment_default_mode_$node_type", 1));
56 $row->setSourceProperty('per_page', $this->variableGet("comment_default_per_page_$node_type", 50));
57 $row->setSourceProperty('anonymous', $this->variableGet("comment_anonymous_$node_type", FALSE));
58 $row->setSourceProperty('form_location', $this->variableGet("comment_form_location_$node_type", CommentItemInterface::FORM_BELOW));
59 $row->setSourceProperty('preview', $this->variableGet("comment_preview_$node_type", TRUE));
60 $row->setSourceProperty('subject', $this->variableGet("comment_subject_field_$node_type", TRUE));
62 $label = $this->t('@node_type comment', [
63 '@node_type' => $this->nodeTypes[$node_type],
65 $row->setSourceProperty('label', $label);
67 return parent::prepareRow($row);
73 public function fields() {
75 'label' => $this->t('The label of the comment type.'),
76 'bundle' => $this->t('Bundle ID of the comment type.'),
77 'node_type' => $this->t('The node type to which this comment type is attached.'),
78 'default_mode' => $this->t('Default comment mode.'),
79 'per_page' => $this->t('Number of comments visible per page.'),
80 'anonymous' => $this->t('Whether anonymous comments are allowed.'),
81 'form_location' => $this->t('Location of the comment form.'),
82 'preview' => $this->t('Whether previews are enabled for the comment type.'),
83 'subject' => $this->t('Whether a subject field is enabled for the comment type.'),
90 public function getIds() {