3 namespace Drupal\comment\Plugin\migrate\source\d6;
5 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
6 use Drupal\migrate\Plugin\migrate\source\DummyQueryTrait;
10 * id = "d6_comment_variable"
13 class CommentVariable extends DrupalSqlBase {
20 protected function initializeIterator() {
21 return new \ArrayIterator($this->getCommentVariables());
27 public function count() {
28 return count($this->getCommentVariables());
32 * Retrieves the values of the comment variables grouped by node type.
36 protected function getCommentVariables() {
37 $comment_prefixes = array_keys($this->commentPrefixes());
39 $node_types = $this->select('node_type', 'nt')
40 ->fields('nt', ['type'])
43 foreach ($node_types as $node_type) {
44 foreach ($comment_prefixes as $prefix) {
45 $variables[] = $prefix . '_' . $node_type;
49 $values = $this->select('variable', 'v')
50 ->fields('v', ['name', 'value'])
51 ->condition('name', $variables, 'IN')
54 foreach ($node_types as $node_type) {
55 foreach ($comment_prefixes as $prefix) {
56 $name = $prefix . '_' . $node_type;
57 if (isset($values[$name])) {
58 $return[$node_type][$prefix] = unserialize($values[$name]);
62 // The return key will not be used so move it inside the row. This could
63 // not be done sooner because otherwise empty rows would be created with
64 // just the node type in it.
65 foreach ($return as $node_type => $data) {
66 $return[$node_type]['node_type'] = $node_type;
67 $return[$node_type]['comment_type'] = empty($data['comment_subject_field']) ?
68 'comment_no_subject' : 'comment';
76 public function fields() {
77 return $this->commentPrefixes() + [
78 'node_type' => $this->t('The node type'),
79 'comment_type' => $this->t('The comment type'),
84 * Comment related data for fields.
86 protected function commentPrefixes() {
88 'comment' => $this->t('Default comment setting'),
89 'comment_default_mode' => $this->t('Default display mode'),
90 'comment_default_order' => $this->t('Default display order'),
91 'comment_default_per_page' => $this->t('Default comments per page'),
92 'comment_controls' => $this->t('Comment controls'),
93 'comment_anonymous' => $this->t('Anonymous commenting'),
94 'comment_subject_field' => $this->t('Comment subject field'),
95 'comment_preview' => $this->t('Preview comment'),
96 'comment_form_location' => $this->t('Location of comment submission form'),
103 public function getIds() {
104 $ids['node_type']['type'] = 'string';