3 namespace Drupal\field\Plugin\migrate\source\d7;
5 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
8 * The field instance per view mode source class.
11 * id = "d7_field_instance_per_view_mode",
12 * source_provider = "field"
15 class FieldInstancePerViewMode extends DrupalSqlBase {
20 protected function initializeIterator() {
22 $result = $this->prepareQuery()->execute();
23 foreach ($result as $field_instance) {
24 $data = unserialize($field_instance['data']);
25 // We don't need to include the serialized data in the returned rows.
26 unset($field_instance['data']);
28 foreach ($data['display'] as $view_mode => $info) {
29 // Rename type to formatter_type in the info array.
30 $info['formatter_type'] = $info['type'];
33 $rows[] = array_merge($field_instance, $info, [
34 'view_mode' => $view_mode,
38 return new \ArrayIterator($rows);
44 public function query() {
45 $query = $this->select('field_config_instance', 'fci')
46 ->fields('fci', ['entity_type', 'bundle', 'field_name', 'data'])
47 ->fields('fc', ['type']);
48 $query->join('field_config', 'fc', 'fc.field_name = fci.field_name');
55 public function fields() {
57 'entity_type' => $this->t('The entity type ID.'),
58 'bundle' => $this->t('The bundle ID.'),
59 'field_name' => $this->t('Machine name of the field.'),
60 'view_mode' => $this->t('The original machine name of the view mode.'),
61 'label' => $this->t('The display label of the field.'),
62 'type' => $this->t('The field ID.'),
63 'formatter_type' => $this->t('The formatter ID.'),
64 'settings' => $this->t('Array of formatter-specific settings.'),
65 'module' => $this->t('The module providing the formatter.'),
66 'weight' => $this->t('Display weight of the field.'),
73 public function getIds() {
93 public function count() {
94 return $this->initializeIterator()->count();