Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / node / src / Plugin / migrate / source / d6 / NodeType.php
1 <?php
2
3 namespace Drupal\node\Plugin\migrate\source\d6;
4
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
7
8 /**
9  * Drupal 6 Node types source from database.
10  *
11  * @MigrateSource(
12  *   id = "d6_node_type",
13  *   source_module = "node"
14  * )
15  */
16 class NodeType extends DrupalSqlBase {
17
18   /**
19    * The teaser length
20    *
21    * @var int
22    */
23   protected $teaserLength;
24
25   /**
26    * Node preview optional / required.
27    *
28    * @var int
29    */
30   protected $nodePreview;
31
32   /**
33    * An array of theme settings.
34    *
35    * @var array
36    */
37   protected $themeSettings;
38
39   /**
40    * {@inheritdoc}
41    */
42   public function query() {
43     return $this->select('node_type', 't')
44       ->fields('t', [
45         'type',
46         'name',
47         'module',
48         'description',
49         'help',
50         'title_label',
51         'has_body',
52         'body_label',
53         'min_word_count',
54         'custom',
55         'modified',
56         'locked',
57         'orig_type',
58       ])
59       ->orderBy('t.type');
60   }
61
62   /**
63    * {@inheritdoc}
64    */
65   public function fields() {
66     $fields = [
67       'type' => $this->t('Machine name of the node type.'),
68       'name' => $this->t('Human name of the node type.'),
69       'module' => $this->t('The module providing the node type.'),
70       'description' => $this->t('Description of the node type.'),
71       'help' => $this->t('Help text for the node type.'),
72       'title_label' => $this->t('Title label.'),
73       'has_body' => $this->t('Flag indicating the node type has a body field.'),
74       'body_label' => $this->t('Body label.'),
75       'min_word_count' => $this->t('Minimum word count for the body field.'),
76       'custom' => $this->t('Flag.'),
77       'modified' => $this->t('Flag.'),
78       'locked' => $this->t('Flag.'),
79       'orig_type' => $this->t('The original type.'),
80       'teaser_length' => $this->t('Teaser length'),
81     ];
82     if ($this->moduleExists('comment')) {
83       $fields += $this->getCommentFields();
84     }
85     return $fields;
86   }
87
88   /**
89    * Returns the fields containing comment settings for each node type.
90    *
91    * @return string[]
92    *   An associative array of field descriptions, keyed by field.
93    */
94   protected function getCommentFields() {
95     return [
96       'comment' => $this->t('Default comment setting'),
97       'comment_default_mode' => $this->t('Default display mode'),
98       'comment_default_per_page' => $this->t('Default comments per page'),
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'),
103     ];
104   }
105
106   /**
107    * {@inheritdoc}
108    */
109   protected function initializeIterator() {
110     $this->teaserLength = $this->variableGet('teaser_length', 600);
111     $this->nodePreview = $this->variableGet('node_preview', 0);
112     $this->themeSettings = $this->variableGet('theme_settings', []);
113     return parent::initializeIterator();
114   }
115
116   /**
117    * {@inheritdoc}
118    */
119   public function prepareRow(Row $row) {
120     $row->setSourceProperty('teaser_length', $this->teaserLength);
121     $row->setSourceProperty('node_preview', $this->nodePreview);
122
123     $type = $row->getSourceProperty('type');
124     $source_options = $this->variableGet('node_options_' . $type, ['promote', 'sticky']);
125     $options = [];
126     foreach (['promote', 'sticky', 'status', 'revision'] as $item) {
127       $options[$item] = in_array($item, $source_options);
128     }
129     $row->setSourceProperty('options', $options);
130     $submitted = isset($this->themeSettings['toggle_node_info_' . $type]) ? $this->themeSettings['toggle_node_info_' . $type] : FALSE;
131     $row->setSourceProperty('display_submitted', $submitted);
132
133     if ($default_node_menu = $this->variableGet('menu_default_node_menu', NULL)) {
134       $row->setSourceProperty('available_menus', [$default_node_menu]);
135       $row->setSourceProperty('parent', $default_node_menu . ':');
136     }
137
138     if ($this->moduleExists('comment')) {
139       foreach (array_keys($this->getCommentFields()) as $field) {
140         $row->setSourceProperty($field, $this->variableGet($field . '_' . $type, NULL));
141       }
142     }
143
144     return parent::prepareRow($row);
145   }
146
147   /**
148    * {@inheritdoc}
149    */
150   public function getIds() {
151     $ids['type']['type'] = 'string';
152     return $ids;
153   }
154
155 }