3 namespace Drupal\field\Plugin\migrate\source\d6;
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
9 * Drupal 6 field source from database.
13 * source_provider = "content"
16 class Field extends DrupalSqlBase {
21 public function query() {
22 $query = $this->select('content_node_field', 'cnf')
36 // Only import fields which are actually being used.
37 $query->innerJoin('content_node_field_instance', 'cnfi', 'cnfi.field_name = cnf.field_name');
45 public function fields() {
47 'field_name' => $this->t('Field name'),
48 'type' => $this->t('Type (text, integer, ....)'),
49 'widget_type' => $this->t('An instance-specific widget type'),
50 'global_settings' => $this->t('Global settings. Shared with every field instance.'),
51 'required' => $this->t('Required'),
52 'multiple' => $this->t('Multiple'),
53 'db_storage' => $this->t('DB storage'),
54 'module' => $this->t('Module'),
55 'db_columns' => $this->t('DB Columns'),
56 'active' => $this->t('Active'),
57 'locked' => $this->t('Locked'),
64 public function prepareRow(Row $row) {
65 // The instance widget_type helps determine what D8 field type we'll use.
66 // Identify the distinct widget_types being used in D6.
67 $widget_types = $this->select('content_node_field_instance', 'cnfi')
68 ->fields('cnfi', ['widget_type'])
69 ->condition('field_name', $row->getSourceProperty('field_name'))
71 ->orderBy('widget_type')
74 // Arbitrarily use the first widget_type - if there are multiples, let the
76 $row->setSourceProperty('widget_type', $widget_types[0]);
77 if (count($widget_types) > 1) {
78 $this->migration->getIdMap()->saveMessage(
79 ['field_name' => $row->getSourceProperty('field_name')],
80 $this->t('Widget types @types are used in Drupal 6 field instances: widget type @selected_type applied to the Drupal 8 base field', [
81 '@types' => implode(', ', $widget_types),
82 '@selected_type' => $widget_types[0],
88 $global_settings = unserialize($row->getSourceProperty('global_settings'));
89 $db_columns = unserialize($row->getSourceProperty('db_columns'));
90 $row->setSourceProperty('global_settings', $global_settings);
91 $row->setSourceProperty('db_columns', $db_columns);
92 return parent::prepareRow($row);
98 public function getIds() {
99 $ids['field_name'] = [