diff --git a/core/modules/field/migration_templates/d7_field_formatter_settings.yml b/core/modules/field/migration_templates/d7_field_formatter_settings.yml index 126fd29..3055e47 100644 --- a/core/modules/field/migration_templates/d7_field_formatter_settings.yml +++ b/core/modules/field/migration_templates/d7_field_formatter_settings.yml @@ -44,14 +44,14 @@ process: map: full: default field_name: field_name - "options/label": label - "options/weight": weight + "options/label": 'formatter/label' + "options/weight": 'formatter/weight' # The formatter to use. "options/type": - plugin: static_map bypass: true - source: formatter_type + source: 'formatter/type' map: date_default: datetime_default email_default: email_mailto @@ -69,7 +69,7 @@ process: method: row "options/settings": plugin: default_value - source: settings + source: 'formatter/settings' default_value: [] "options/third_party_settings": 'constants/third_party_settings' destination: diff --git a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php index 46b6e29..8b86a94 100644 --- a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php +++ b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php @@ -79,6 +79,7 @@ public function fields() { 'bundle' => $this->t('The entity bundle.'), 'data' => $this->t('The field instance data.'), 'deleted' => $this->t('Deleted'), + 'type' => $this->t('The field type'), 'field_definition' => $this->t('The field definition.'), ]; } @@ -140,4 +141,11 @@ public function getIds() { ]; } + /** + * {@inheritdoc} + */ + public function count() { + return $this->initializeIterator()->count(); + } + } diff --git a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerFormDisplay.php b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerFormDisplay.php index ac599ec..6ada96f 100644 --- a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerFormDisplay.php +++ b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerFormDisplay.php @@ -2,58 +2,17 @@ namespace Drupal\field\Plugin\migrate\source\d7; -use Drupal\migrate\Row; -use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; +use Drupal\field\Plugin\migrate\source\d7\FieldInstance; /** * The field instance per form display source class. * * @MigrateSource( - * id = "d7_field_instance_per_form_display" + * id = "d7_field_instance_per_form_display", + * source_provider = "field" * ) */ -class FieldInstancePerFormDisplay extends DrupalSqlBase { - - /** - * {@inheritdoc} - */ - public function query() { - $query = $this->select('field_config_instance', 'fci') - ->fields('fci', [ - 'field_name', - 'bundle', - 'data', - 'entity_type' - ]) - ->fields('fc', [ - 'type', - 'module', - ]); - $query->join('field_config', 'fc', 'fci.field_id = fc.id'); - return $query; - } - - /** - * {@inheritdoc} - */ - public function prepareRow(Row $row) { - $data = unserialize($row->getSourceProperty('data')); - $row->setSourceProperty('widget', $data['widget']); - $row->setSourceProperty('widget_settings', $data['widget']['settings']); - return parent::prepareRow($row); - } - - /** - * {@inheritdoc} - */ - public function fields() { - return [ - 'field_name' => $this->t('The machine name of field.'), - 'bundle' => $this->t('Content type where this field is used.'), - 'data' => $this->t('Field configuration data.'), - 'entity_type' => $this->t('The entity type.'), - ]; - } +class FieldInstancePerFormDisplay extends FieldInstance { /** * {@inheritdoc} diff --git a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerViewMode.php b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerViewMode.php index 7339e76..f61c011 100644 --- a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerViewMode.php +++ b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerViewMode.php @@ -2,7 +2,7 @@ namespace Drupal\field\Plugin\migrate\source\d7; -use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; +use Drupal\field\Plugin\migrate\source\d7\FieldInstance; /** * The field instance per view mode source class. @@ -12,26 +12,21 @@ * source_provider = "field" * ) */ -class FieldInstancePerViewMode extends DrupalSqlBase { +class FieldInstancePerViewMode extends FieldInstance { /** * {@inheritdoc} */ protected function initializeIterator() { - $rows = []; - $result = $this->prepareQuery()->execute(); - foreach ($result as $field_instance) { - $data = unserialize($field_instance['data']); - // We don't need to include the serialized data in the returned rows. - unset($field_instance['data']); - - foreach ($data['display'] as $view_mode => $info) { - // Rename type to formatter_type in the info array. - $info['formatter_type'] = $info['type']; - unset($info['type']); + $instances = parent::initializeIterator(); - $rows[] = array_merge($field_instance, $info, [ + $rows = []; + foreach ($instances->getArrayCopy() as $instance) { + $data = unserialize($instance['data']); + foreach ($data['display'] as $view_mode => $formatter) { + $rows[] = array_merge($instance, [ 'view_mode' => $view_mode, + 'formatter' => $formatter, ]); } } @@ -41,30 +36,11 @@ protected function initializeIterator() { /** * {@inheritdoc} */ - public function query() { - $query = $this->select('field_config_instance', 'fci') - ->fields('fci', ['entity_type', 'bundle', 'field_name', 'data']) - ->fields('fc', ['type']); - $query->join('field_config', 'fc', 'fc.field_name = fci.field_name'); - return $query; - } - - /** - * {@inheritdoc} - */ public function fields() { - return [ - 'entity_type' => $this->t('The entity type ID.'), - 'bundle' => $this->t('The bundle ID.'), - 'field_name' => $this->t('Machine name of the field.'), + return array_merge(parent::fields(), [ '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 field ID.'), - 'formatter_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.'), - ]; + 'formatter' => $this->t('The formatter settings.'), + ]); } /** @@ -87,11 +63,4 @@ public function getIds() { ]; } - /** - * {@inheritdoc} - */ - public function count() { - return $this->initializeIterator()->count(); - } - } diff --git a/core/modules/field/src/Plugin/migrate/source/d7/ViewMode.php b/core/modules/field/src/Plugin/migrate/source/d7/ViewMode.php index 3dd037c..de44ce6 100644 --- a/core/modules/field/src/Plugin/migrate/source/d7/ViewMode.php +++ b/core/modules/field/src/Plugin/migrate/source/d7/ViewMode.php @@ -2,31 +2,35 @@ namespace Drupal\field\Plugin\migrate\source\d7; -use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; +use Drupal\field\Plugin\migrate\source\d7\FieldInstance; /** + * The view mode source class. + * * @MigrateSource( - * id = "d7_view_mode" + * id = "d7_view_mode", + * source_provider = "field" * ) */ -class ViewMode extends DrupalSqlBase { +class ViewMode extends FieldInstance { /** * {@inheritdoc} */ protected function initializeIterator() { + $instances = parent::initializeIterator(); + $rows = []; - $result = $this->prepareQuery()->execute(); - foreach ($result as $field_instance) { - $data = unserialize($field_instance['data']); + foreach ($instances->getArrayCopy() as $instance) { + $data = unserialize($instance['data']); foreach (array_keys($data['display']) as $view_mode) { - $key = $field_instance['entity_type'] . '.' . $view_mode; - $rows[$key] = [ - 'entity_type' => $field_instance['entity_type'], + $key = $instance['entity_type'] . '.' . $view_mode; + $rows[$key] = array_merge($instance, [ 'view_mode' => $view_mode, - ]; + ]); } } + return new \ArrayIterator($rows); } @@ -34,18 +38,9 @@ protected function initializeIterator() { * {@inheritdoc} */ public function fields() { - return [ + return array_merge(parent::fields(), [ 'view_mode' => $this->t('The view mode ID.'), - 'entity_type' => $this->t('The entity type ID.'), - ]; - } - - /** - * {@inheritdoc} - */ - public function query() { - return $this->select('field_config_instance', 'fci') - ->fields('fci', ['entity_type', 'data']); + ]); } /** @@ -62,11 +57,4 @@ public function getIds() { ]; } - /** - * {@inheritdoc} - */ - public function count() { - return $this->initializeIterator()->count(); - } - }