View source
<?php
namespace Drupal\field\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
class FieldInstancePerViewMode extends DrupalSqlBase {
protected function initializeIterator() {
$rows = array();
$result = $this
->prepareQuery()
->execute();
foreach ($result as $field_instance) {
$data = unserialize($field_instance['data']);
unset($field_instance['data']);
foreach ($data['display'] as $view_mode => $info) {
$rows[] = array_merge($field_instance, $info, array(
'view_mode' => $view_mode,
));
}
}
return new \ArrayIterator($rows);
}
public function query() {
return $this
->select('field_config_instance', 'fci')
->fields('fci', array(
'entity_type',
'bundle',
'field_name',
'data',
));
}
public function fields() {
return array(
'entity_type' => $this
->t('The entity type ID.'),
'bundle' => $this
->t('The bundle ID.'),
'field_name' => $this
->t('Machine name of the field.'),
'view_mode' => $this
->t('The original machine name of the view mode.'),
'label' => $this
->t('The display label of the field.'),
'type' => $this
->t('The formatter ID.'),
'settings' => $this
->t('Array of formatter-specific settings.'),
'module' => $this
->t('The module providing the formatter.'),
'weight' => $this
->t('Display weight of the field.'),
);
}
public function getIds() {
return array(
'entity_type' => array(
'type' => 'string',
),
'bundle' => array(
'type' => 'string',
),
'view_mode' => array(
'type' => 'string',
),
'field_name' => array(
'type' => 'string',
),
);
}
public function count() {
return $this
->initializeIterator()
->count();
}
}