Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / comment / src / Plugin / migrate / source / d7 / CommentType.php
1 <?php
2
3 namespace Drupal\comment\Plugin\migrate\source\d7;
4
5 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
6 use Drupal\migrate\Row;
7 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
8
9 /**
10  * Drupal 7 comment type source from database.
11  *
12  * @MigrateSource(
13  *   id = "d7_comment_type",
14  *   source_provider = "comment"
15  * )
16  */
17 class CommentType extends DrupalSqlBase {
18
19   /**
20    * A map of D7 node types to their labels.
21    *
22    * @var string[]
23    */
24   protected $nodeTypes = [];
25
26   /**
27    * {@inheritdoc}
28    */
29   public function query() {
30     return $this->select('field_config_instance', 'fci')
31       ->distinct()
32       ->fields('fci', ['bundle'])
33       ->condition('fci.entity_type', 'comment');
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   protected function initializeIterator() {
40     $this->nodeTypes = $this->select('node_type', 'nt')
41       ->fields('nt', ['type', 'name'])
42       ->execute()
43       ->fetchAllKeyed();
44
45     return parent::initializeIterator();
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function prepareRow(Row $row) {
52     $node_type = substr($row->getSourceProperty('bundle'), 13);
53     $row->setSourceProperty('node_type', $node_type);
54
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));
61
62     $label = $this->t('@node_type comment', [
63       '@node_type' => $this->nodeTypes[$node_type],
64     ]);
65     $row->setSourceProperty('label', $label);
66
67     return parent::prepareRow($row);
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   public function fields() {
74     return [
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.'),
84     ];
85   }
86
87   /**
88    * {@inheritdoc}
89    */
90   public function getIds() {
91     return [
92       'bundle' => [
93         'type' => 'string',
94       ],
95     ];
96   }
97
98 }