3 namespace Drupal\node\Plugin\migrate\source\d6;
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
9 * Drupal 6 Node types source from database.
12 * id = "d6_node_type",
13 * source_module = "node"
16 class NodeType extends DrupalSqlBase {
23 protected $teaserLength;
26 * Node preview optional / required.
30 protected $nodePreview;
33 * An array of theme settings.
37 protected $themeSettings;
42 public function query() {
43 return $this->select('node_type', 't')
65 public function 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'),
82 if ($this->moduleExists('comment')) {
83 $fields += $this->getCommentFields();
89 * Returns the fields containing comment settings for each node type.
92 * An associative array of field descriptions, keyed by field.
94 protected function getCommentFields() {
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'),
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();
119 public function prepareRow(Row $row) {
120 $row->setSourceProperty('teaser_length', $this->teaserLength);
121 $row->setSourceProperty('node_preview', $this->nodePreview);
123 $type = $row->getSourceProperty('type');
124 $source_options = $this->variableGet('node_options_' . $type, ['promote', 'sticky']);
126 foreach (['promote', 'sticky', 'status', 'revision'] as $item) {
127 $options[$item] = in_array($item, $source_options);
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);
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 . ':');
138 if ($this->moduleExists('comment')) {
139 foreach (array_keys($this->getCommentFields()) as $field) {
140 $row->setSourceProperty($field, $this->variableGet($field . '_' . $type, NULL));
144 return parent::prepareRow($row);
150 public function getIds() {
151 $ids['type']['type'] = 'string';