3 namespace Drupal\comment\Plugin\migrate\source\d6;
5 @trigger_error('CommentVariable is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d6\NodeType instead.', E_USER_DEPRECATED);
7 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
8 use Drupal\migrate\Plugin\migrate\source\DummyQueryTrait;
12 * id = "d6_comment_variable",
13 * source_module = "comment"
16 * @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use
17 * \Drupal\node\Plugin\migrate\source\d6\NodeType instead.
19 class CommentVariable extends DrupalSqlBase {
26 protected function initializeIterator() {
27 return new \ArrayIterator($this->getCommentVariables());
33 public function count($refresh = FALSE) {
34 return count($this->getCommentVariables());
38 * Retrieves the values of the comment variables grouped by node type.
42 protected function getCommentVariables() {
43 $comment_prefixes = array_keys($this->commentPrefixes());
45 $node_types = $this->select('node_type', 'nt')
46 ->fields('nt', ['type'])
49 foreach ($node_types as $node_type) {
50 foreach ($comment_prefixes as $prefix) {
51 $variables[] = $prefix . '_' . $node_type;
55 $values = $this->select('variable', 'v')
56 ->fields('v', ['name', 'value'])
57 ->condition('name', $variables, 'IN')
60 foreach ($node_types as $node_type) {
61 foreach ($comment_prefixes as $prefix) {
62 $name = $prefix . '_' . $node_type;
63 if (isset($values[$name])) {
64 $return[$node_type][$prefix] = unserialize($values[$name]);
68 // The return key will not be used so move it inside the row. This could
69 // not be done sooner because otherwise empty rows would be created with
70 // just the node type in it.
71 foreach ($return as $node_type => $data) {
72 $return[$node_type]['node_type'] = $node_type;
73 $return[$node_type]['comment_type'] = empty($data['comment_subject_field']) ?
74 'comment_no_subject' : 'comment';
82 public function fields() {
83 return $this->commentPrefixes() + [
84 'node_type' => $this->t('The node type'),
85 'comment_type' => $this->t('The comment type'),
90 * Comment related data for fields.
92 protected function commentPrefixes() {
94 'comment' => $this->t('Default comment setting'),
95 'comment_default_mode' => $this->t('Default display mode'),
96 'comment_default_order' => $this->t('Default display order'),
97 'comment_default_per_page' => $this->t('Default comments per page'),
98 'comment_controls' => $this->t('Comment controls'),
99 'comment_anonymous' => $this->t('Anonymous commenting'),
100 'comment_subject_field' => $this->t('Comment subject field'),
101 'comment_preview' => $this->t('Preview comment'),
102 'comment_form_location' => $this->t('Location of comment submission form'),
109 public function getIds() {
110 $ids['node_type']['type'] = 'string';