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_provider = "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'),
62 protected function initializeIterator() {
63 $this->teaserLength = $this->variableGet('teaser_length', 600);
64 $this->nodePreview = $this->variableGet('node_preview', 0);
65 return parent::initializeIterator();
71 public function prepareRow(Row $row) {
72 $row->setSourceProperty('teaser_length', $this->teaserLength);
73 $row->setSourceProperty('node_preview', $this->nodePreview);
75 $type = $row->getSourceProperty('type');
76 $source_options = $this->variableGet('node_options_' . $type, ['promote', 'sticky']);
78 foreach (['promote', 'sticky', 'status', 'revision'] as $item) {
79 $options[$item] = in_array($item, $source_options);
81 $row->setSourceProperty('options', $options);
83 // Don't create a body field until we prove that this node type has one.
84 $row->setSourceProperty('create_body', FALSE);
86 if ($this->moduleExists('field')) {
87 // Find body field for this node type.
88 $body = $this->select('field_config_instance', 'fci')
89 ->fields('fci', ['data'])
90 ->condition('entity_type', 'node')
91 ->condition('bundle', $row->getSourceProperty('type'))
92 ->condition('field_name', 'body')
96 $row->setSourceProperty('create_body', TRUE);
97 $body['data'] = unserialize($body['data']);
98 $row->setSourceProperty('body_label', $body['data']['label']);
102 $row->setSourceProperty('display_submitted', $this->variableGet('node_submitted_' . $type, TRUE));
104 if ($menu_options = $this->variableGet('menu_options_' . $type, NULL)) {
105 $row->setSourceProperty('available_menus', $menu_options);
107 if ($parent = $this->variableGet('menu_parent_' . $type, NULL)) {
108 $row->setSourceProperty('parent', $parent . ':');
110 return parent::prepareRow($row);
116 public function getIds() {
117 $ids['type']['type'] = 'string';