3 namespace Drupal\field\Plugin\migrate\source\d7;
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
9 * Drupal 7 field instances source from database.
12 * id = "d7_field_instance",
13 * source_provider = "field"
16 class FieldInstance extends DrupalSqlBase {
21 public function query() {
22 $query = $this->select('field_config_instance', 'fci')
24 ->condition('fci.deleted', 0)
25 ->condition('fc.active', 1)
26 ->condition('fc.deleted', 0)
27 ->condition('fc.storage_active', 1)
28 ->fields('fc', ['type']);
30 $query->innerJoin('field_config', 'fc', 'fci.field_id = fc.id');
31 $query->addField('fc', 'data', 'field_data');
33 // Optionally filter by entity type and bundle.
34 if (isset($this->configuration['entity_type'])) {
35 $query->condition('fci.entity_type', $this->configuration['entity_type']);
37 if (isset($this->configuration['bundle'])) {
38 $query->condition('fci.bundle', $this->configuration['bundle']);
48 public function fields() {
50 'field_name' => $this->t('The machine name of field.'),
51 'entity_type' => $this->t('The entity type.'),
52 'bundle' => $this->t('The entity bundle.'),
53 'default_value' => $this->t('Default value'),
54 'instance_settings' => $this->t('Field instance settings.'),
55 'widget_settings' => $this->t('Widget settings.'),
56 'display_settings' => $this->t('Display settings.'),
57 'field_settings' => $this->t('Field settings.'),
64 public function prepareRow(Row $row) {
65 $data = unserialize($row->getSourceProperty('data'));
67 $row->setSourceProperty('label', $data['label']);
68 $row->setSourceProperty('description', $data['description']);
69 $row->setSourceProperty('required', $data['required']);
71 $default_value = !empty($data['default_value']) ? $data['default_value'] : [];
72 if ($data['widget']['type'] == 'email_textfield' && $default_value) {
73 $default_value[0]['value'] = $default_value[0]['email'];
74 unset($default_value[0]['email']);
76 $row->setSourceProperty('default_value', $default_value);
79 $row->setSourceProperty('instance_settings', $data['settings']);
80 $row->setSourceProperty('widget_settings', $data['widget']);
81 $row->setSourceProperty('display_settings', $data['display']);
83 // This is for parity with the d6_field_instance plugin.
84 $row->setSourceProperty('widget_type', $data['widget']['type']);
86 $field_data = unserialize($row->getSourceProperty('field_data'));
87 $row->setSourceProperty('field_settings', $field_data['settings']);
89 $translatable = FALSE;
90 if ($row->getSourceProperty('entity_type') == 'node') {
91 // language_content_type_[bundle] may be
92 // - 0: no language support
93 // - 1: language assignment support
94 // - 2: node translation support
95 // - 4: entity translation support
96 if ($this->variableGet('language_content_type_' . $row->getSourceProperty('bundle'), 0) == 2) {
101 // This is not a node entity. Get the translatable value from the source
102 // field_config table.
103 $data = unserialize($row->getSourceProperty('field_data'));
104 $translatable = $data['translatable'];
106 $row->setSourceProperty('translatable', $translatable);
108 return parent::prepareRow($row);
114 public function getIds() {