3 namespace Drupal\node\Plugin\migrate\source\d7;
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
9 * Drupal 7 Node types source from database.
12 * id = "d7_node_type",
13 * source_module = "node"
16 class NodeType extends DrupalSqlBase {
23 protected $teaserLength;
26 * Node preview optional / required.
30 protected $nodePreview;
35 public function query() {
36 return $this->select('node_type', 't')->fields('t');
42 public function fields() {
44 'type' => $this->t('Machine name of the node type.'),
45 'name' => $this->t('Human name of the node type.'),
46 'description' => $this->t('Description of the node type.'),
47 'help' => $this->t('Help text for the node type.'),
48 'title_label' => $this->t('Title label.'),
49 'disabled' => $this->t('Flag indicating the node type is enable'),
50 'base' => $this->t('base node.'),
51 'custom' => $this->t('Flag.'),
52 'modified' => $this->t('Flag.'),
53 'locked' => $this->t('Flag.'),
54 'orig_type' => $this->t('The original type.'),
55 'teaser_length' => $this->t('Teaser length'),
57 if ($this->moduleExists('comment')) {
58 $fields += $this->getCommentFields();
64 * Returns the fields containing comment settings for each node type.
67 * An associative array of field descriptions, keyed by field.
69 protected function getCommentFields() {
71 'comment' => $this->t('Default comment setting'),
72 'comment_default_mode' => $this->t('Default display mode'),
73 'comment_default_per_page' => $this->t('Default comments per page'),
74 'comment_anonymous' => $this->t('Anonymous commenting'),
75 'comment_subject_field' => $this->t('Comment subject field'),
76 'comment_preview' => $this->t('Preview comment'),
77 'comment_form_location' => $this->t('Location of comment submission form'),
84 protected function initializeIterator() {
85 $this->teaserLength = $this->variableGet('teaser_length', 600);
86 $this->nodePreview = $this->variableGet('node_preview', 0);
87 return parent::initializeIterator();
93 public function prepareRow(Row $row) {
94 $row->setSourceProperty('teaser_length', $this->teaserLength);
95 $row->setSourceProperty('node_preview', $this->nodePreview);
97 $type = $row->getSourceProperty('type');
98 $source_options = $this->variableGet('node_options_' . $type, ['promote', 'sticky']);
100 foreach (['promote', 'sticky', 'status', 'revision'] as $item) {
101 $options[$item] = in_array($item, $source_options);
103 $row->setSourceProperty('options', $options);
105 // Don't create a body field until we prove that this node type has one.
106 $row->setSourceProperty('create_body', FALSE);
108 if ($this->moduleExists('field')) {
109 // Find body field for this node type.
110 $body = $this->select('field_config_instance', 'fci')
111 ->fields('fci', ['data'])
112 ->condition('entity_type', 'node')
113 ->condition('bundle', $row->getSourceProperty('type'))
114 ->condition('field_name', 'body')
118 $row->setSourceProperty('create_body', TRUE);
119 $body['data'] = unserialize($body['data']);
120 $row->setSourceProperty('body_label', $body['data']['label']);
124 $row->setSourceProperty('display_submitted', $this->variableGet('node_submitted_' . $type, TRUE));
126 if ($menu_options = $this->variableGet('menu_options_' . $type, NULL)) {
127 $row->setSourceProperty('available_menus', $menu_options);
129 if ($parent = $this->variableGet('menu_parent_' . $type, NULL)) {
130 $row->setSourceProperty('parent', $parent . ':');
133 if ($this->moduleExists('comment')) {
134 foreach (array_keys($this->getCommentFields()) as $field) {
135 $row->setSourceProperty($field, $this->variableGet($field . '_' . $type, NULL));
139 return parent::prepareRow($row);
145 public function getIds() {
146 $ids['type']['type'] = 'string';