Version 1
[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  * )
14  */
15 class NodeType extends DrupalSqlBase {
16
17   /**
18    * The teaser length
19    *
20    * @var int
21    */
22   protected $teaserLength;
23
24   /**
25    * Node preview optional / required.
26    *
27    * @var int
28    */
29   protected $nodePreview;
30
31   /**
32    * An array of theme settings.
33    *
34    * @var array
35    */
36   protected $themeSettings;
37
38   /**
39    * {@inheritdoc}
40    */
41   public function query() {
42     return $this->select('node_type', 't')
43       ->fields('t', [
44         'type',
45         'name',
46         'module',
47         'description',
48         'help',
49         'title_label',
50         'has_body',
51         'body_label',
52         'min_word_count',
53         'custom',
54         'modified',
55         'locked',
56         'orig_type',
57       ])
58       ->orderBy('t.type');
59   }
60
61   /**
62    * {@inheritdoc}
63    */
64   public function fields() {
65     return [
66       'type' => $this->t('Machine name of the node type.'),
67       'name' => $this->t('Human name of the node type.'),
68       'module' => $this->t('The module providing the node type.'),
69       'description' => $this->t('Description of the node type.'),
70       'help' => $this->t('Help text for the node type.'),
71       'title_label' => $this->t('Title label.'),
72       'has_body' => $this->t('Flag indicating the node type has a body field.'),
73       'body_label' => $this->t('Body label.'),
74       'min_word_count' => $this->t('Minimum word count for the body field.'),
75       'custom' => $this->t('Flag.'),
76       'modified' => $this->t('Flag.'),
77       'locked' => $this->t('Flag.'),
78       'orig_type' => $this->t('The original type.'),
79       'teaser_length' => $this->t('Teaser length'),
80     ];
81   }
82
83   /**
84    * {@inheritdoc}
85    */
86   protected function initializeIterator() {
87     $this->teaserLength = $this->variableGet('teaser_length', 600);
88     $this->nodePreview = $this->variableGet('node_preview', 0);
89     $this->themeSettings = $this->variableGet('theme_settings', []);
90     return parent::initializeIterator();
91   }
92
93   /**
94    * {@inheritdoc}
95    */
96   public function prepareRow(Row $row) {
97     $row->setSourceProperty('teaser_length', $this->teaserLength);
98     $row->setSourceProperty('node_preview', $this->nodePreview);
99
100     $type = $row->getSourceProperty('type');
101     $source_options = $this->variableGet('node_options_' . $type, ['promote', 'sticky']);
102     $options = [];
103     foreach (['promote', 'sticky', 'status', 'revision'] as $item) {
104       $options[$item] = in_array($item, $source_options);
105     }
106     $row->setSourceProperty('options', $options);
107     $submitted = isset($this->themeSettings['toggle_node_info_' . $type]) ? $this->themeSettings['toggle_node_info_' . $type] : FALSE;
108     $row->setSourceProperty('display_submitted', $submitted);
109
110     if ($default_node_menu = $this->variableGet('menu_default_node_menu', NULL)) {
111       $row->setSourceProperty('available_menus', [$default_node_menu]);
112       $row->setSourceProperty('parent', $default_node_menu . ':');
113     }
114     return parent::prepareRow($row);
115   }
116
117   /**
118    * {@inheritdoc}
119    */
120   public function getIds() {
121     $ids['type']['type'] = 'string';
122     return $ids;
123   }
124
125 }