3 namespace Drupal\comment\Plugin\migrate\source\d7;
5 @trigger_error('CommentType is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d7\NodeType instead.', E_USER_DEPRECATED);
7 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
8 use Drupal\migrate\Row;
9 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
12 * Drupal 7 comment type source from database.
15 * id = "d7_comment_type",
16 * source_module = "comment"
19 * @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use
20 * \Drupal\node\Plugin\migrate\source\d7\NodeType instead.
22 class CommentType extends DrupalSqlBase {
25 * A map of D7 node types to their labels.
29 protected $nodeTypes = [];
34 public function query() {
35 return $this->select('field_config_instance', 'fci')
37 ->fields('fci', ['bundle'])
38 ->condition('fci.entity_type', 'comment');
44 protected function initializeIterator() {
45 $this->nodeTypes = $this->select('node_type', 'nt')
46 ->fields('nt', ['type', 'name'])
50 return parent::initializeIterator();
56 public function prepareRow(Row $row) {
57 $node_type = substr($row->getSourceProperty('bundle'), 13);
58 $row->setSourceProperty('node_type', $node_type);
60 $row->setSourceProperty('default_mode', $this->variableGet("comment_default_mode_$node_type", 1));
61 $row->setSourceProperty('per_page', $this->variableGet("comment_default_per_page_$node_type", 50));
62 $row->setSourceProperty('anonymous', $this->variableGet("comment_anonymous_$node_type", FALSE));
63 $row->setSourceProperty('form_location', $this->variableGet("comment_form_location_$node_type", CommentItemInterface::FORM_BELOW));
64 $row->setSourceProperty('preview', $this->variableGet("comment_preview_$node_type", TRUE));
65 $row->setSourceProperty('subject', $this->variableGet("comment_subject_field_$node_type", TRUE));
67 $label = $this->t('@node_type comment', [
68 '@node_type' => $this->nodeTypes[$node_type],
70 $row->setSourceProperty('label', $label);
72 return parent::prepareRow($row);
78 public function fields() {
80 'label' => $this->t('The label of the comment type.'),
81 'bundle' => $this->t('Bundle ID of the comment type.'),
82 'node_type' => $this->t('The node type to which this comment type is attached.'),
83 'default_mode' => $this->t('Default comment mode.'),
84 'per_page' => $this->t('Number of comments visible per page.'),
85 'anonymous' => $this->t('Whether anonymous comments are allowed.'),
86 'form_location' => $this->t('Location of the comment form.'),
87 'preview' => $this->t('Whether previews are enabled for the comment type.'),
88 'subject' => $this->t('Whether a subject field is enabled for the comment type.'),
95 public function getIds() {