3 namespace Drupal\field\Plugin\migrate\source\d6;
5 use Drupal\node\Plugin\migrate\source\d6\ViewModeBase;
8 * The field instance per view mode source class.
11 * id = "d6_field_instance_per_view_mode",
12 * source_provider = "content"
15 class FieldInstancePerViewMode extends ViewModeBase {
20 protected function initializeIterator() {
22 $result = $this->prepareQuery()->execute();
23 while ($field_row = $result->fetchAssoc()) {
24 // These are added to every view mode row.
25 $field_row['display_settings'] = unserialize($field_row['display_settings']);
26 $field_row['widget_settings'] = unserialize($field_row['widget_settings']);
27 $bundle = $field_row['type_name'];
28 $field_name = $field_row['field_name'];
30 foreach ($this->getViewModes() as $view_mode) {
31 // Append to the return value if the row has display settings for this
32 // view mode and the view mode is neither hidden nor excluded.
33 // @see \Drupal\node\Plugin\migrate\source\d6\ViewMode::initializeIterator()
34 if (isset($field_row['display_settings'][$view_mode]) && $field_row['display_settings'][$view_mode]['format'] != 'hidden' && empty($field_row['display_settings'][$view_mode]['exclude'])) {
35 $index = $view_mode . "." . $bundle . "." . $field_name;
36 $rows[$index]['entity_type'] = 'node';
37 $rows[$index]['view_mode'] = $view_mode;
38 $rows[$index]['type_name'] = $bundle;
39 $rows[$index]['field_name'] = $field_name;
40 $rows[$index]['type'] = $field_row['type'];
41 $rows[$index]['module'] = $field_row['module'];
42 $rows[$index]['weight'] = $field_row['weight'];
43 $rows[$index]['label'] = $field_row['display_settings']['label']['format'];
44 $rows[$index]['display_settings'] = $field_row['display_settings'][$view_mode];
45 $rows[$index]['widget_settings'] = $field_row['widget_settings'];
50 return new \ArrayIterator($rows);
56 public function query() {
57 $query = $this->select('content_node_field_instance', 'cnfi')
70 $query->join('content_node_field', 'cnf', 'cnfi.field_name = cnf.field_name');
71 $query->orderBy('cnfi.weight');
79 public function fields() {
81 'field_name' => $this->t('The machine name of field.'),
82 'type_name' => $this->t('Content type where this field is used.'),
83 'weight' => $this->t('Weight.'),
84 'label' => $this->t('A name to show.'),
85 'widget_type' => $this->t('Widget type.'),
86 'widget_settings' => $this->t('Serialize data with widget settings.'),
87 'display_settings' => $this->t('Serialize data with display settings.'),
88 'description' => $this->t('A description of field.'),
89 'widget_module' => $this->t('Module that implements widget.'),
90 'widget_active' => $this->t('Status of widget'),
97 public function getIds() {
98 $ids['type_name']['type'] = 'string';
99 $ids['view_mode']['type'] = 'string';
100 $ids['entity_type']['type'] = 'string';
101 $ids['field_name']['type'] = 'string';