Security update for Core, with self-updated composer
[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 @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);
6
7 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
8 use Drupal\migrate\Row;
9 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
10
11 /**
12  * Drupal 7 comment type source from database.
13  *
14  * @MigrateSource(
15  *   id = "d7_comment_type",
16  *   source_module = "comment"
17  * )
18  *
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.
21  */
22 class CommentType extends DrupalSqlBase {
23
24   /**
25    * A map of D7 node types to their labels.
26    *
27    * @var string[]
28    */
29   protected $nodeTypes = [];
30
31   /**
32    * {@inheritdoc}
33    */
34   public function query() {
35     return $this->select('field_config_instance', 'fci')
36       ->distinct()
37       ->fields('fci', ['bundle'])
38       ->condition('fci.entity_type', 'comment');
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   protected function initializeIterator() {
45     $this->nodeTypes = $this->select('node_type', 'nt')
46       ->fields('nt', ['type', 'name'])
47       ->execute()
48       ->fetchAllKeyed();
49
50     return parent::initializeIterator();
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function prepareRow(Row $row) {
57     $node_type = substr($row->getSourceProperty('bundle'), 13);
58     $row->setSourceProperty('node_type', $node_type);
59
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));
66
67     $label = $this->t('@node_type comment', [
68       '@node_type' => $this->nodeTypes[$node_type],
69     ]);
70     $row->setSourceProperty('label', $label);
71
72     return parent::prepareRow($row);
73   }
74
75   /**
76    * {@inheritdoc}
77    */
78   public function fields() {
79     return [
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.'),
89     ];
90   }
91
92   /**
93    * {@inheritdoc}
94    */
95   public function getIds() {
96     return [
97       'bundle' => [
98         'type' => 'string',
99       ],
100     ];
101   }
102
103 }