Commit f2585a01 authored by webchick's avatar webchick

Issue #2416765 by phenaproxima, miguelc303, hussainweb, mikeryan, benjy, chx:...

Issue #2416765 by phenaproxima, miguelc303, hussainweb, mikeryan, benjy, chx: Migrate Drupal 7 Field/Instance/View mode settings
parent 9f732116
......@@ -37,3 +37,35 @@ migrate.source.d6_field_instance_per_view_mode:
constants:
type: migrate_entity_constant
label: 'Constants'
migrate.source.d7_field:
type: migrate_source_sql
label: 'Drupal 7 field'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'
migrate.source.d7_field_instance:
type: migrate_source_sql
label: 'Drupal 7 field instance'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'
migrate.source.d7_field_instance_per_form_display:
type: migrate_source_sql
label: 'Drupal 7 field instance per form display'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'
migrate.source.d7_field_instance_per_view_mode:
type: migrate_source_sql
label: 'Drupal 7 field instance per view mode'
mapping:
constants:
type: migrate_entity_constant
label: 'Constants'
id: d7_field
label: Drupal 7 field configuration
migration_tags:
- Drupal 7
source:
plugin: d7_field
constants:
status: true
langcode: und
process:
entity_type: entity_type
status: 'constants/status'
langcode: 'constants/langcode'
field_name: field_name
type:
plugin: static_map
source: type
map:
date: datetime
datestamp: datetime
datetime: datetime
email: email
file: file
image: image
link_field: link
list_boolean: boolean
list_integer: list_integer
list_text: list_string
number_integer: integer
number_decimal: decimal
number_float: float
phone: telephone
taxonomy_term_reference: entity_reference
text: text
text_long: text_long
text_with_summary: text_with_summary
translatable: translatable
cardinality: cardinality
settings:
plugin: d7_field_settings
destination:
plugin: entity:field_storage_config
id: d7_field_formatter_settings
label: Drupal 7 field formatter configuration
migration_tags:
- Drupal 7
source:
plugin: d7_field_instance_per_view_mode
constants:
third_party_settings: { }
process:
# We skip field types that don't exist because they weren't migrated by the
# field migration.
field_type_exists:
-
plugin: migration
migration: d7_field
source:
- field_name
- entity_type
-
plugin: extract
index:
- 0
-
plugin: skip_on_empty
method: row
entity_type: entity_type
bundle: bundle
view_mode:
-
plugin: migration
migration: d7_view_modes
source:
- entity_type
- view_mode
-
plugin: extract
index:
- 1
-
plugin: static_map
bypass: true
map:
full: default
field_name: field_name
"options/label": label
"options/weight": weight
# The formatter to use.
"options/type":
-
plugin: static_map
bypass: true
source: type
map:
date_default: datetime_default
email_default: email_mailto
# 0 should cause the row to be skipped by the next plugin in the
# pipeline.
hidden: 0
link_default: link
phone: basic_string
taxonomy_term_reference_link: entity_reference_label
-
plugin: skip_on_empty
method: row
"options/settings": settings
"options/third_party_settings": 'constants/third_party_settings'
destination:
plugin: component_entity_display
migration_dependencies:
required:
- d7_field_instance
- d7_view_modes
id: d7_field_instance
migration_tags:
- Drupal 7
source:
plugin: d7_field_instance
constants:
status: true
process:
entity_type: entity_type
field_name: field_name
bundle: bundle
label: label
description: description
required: required
status: 'constants/status'
settings:
plugin: d7_field_instance_settings
source:
- instance_settings
- widget_settings
default_value_function: ''
default_value:
plugin: d7_field_instance_defaults
source:
- default_value
- widget_settings
destination:
plugin: entity:field_config
migration_dependencies:
required:
- d7_field
id: d7_field_instance_widget_settings
label: Drupal 7 field instance widget configuration
migration_tags:
- Drupal 7
source:
plugin: d7_field_instance_per_form_display
constants:
form_mode: default
third_party_settings: { }
process:
# We skip field types that don't exist because they weren't migrated by the
# field migration.
field_type_exists:
-
plugin: migration
migration: d7_field
source:
- entity_type
- field_name
-
plugin: extract
index:
- 1
-
plugin: skip_on_empty
method: row
bundle: bundle
form_mode: 'constants/form_mode'
field_name: field_name
entity_type: entity_type
'options/weight': 'widget/weight'
'options/type':
type:
plugin: static_map
bypass: true
source: 'widget/type'
map:
link_field: link_default
email_textfield: email_default
date_select: datetime_default
date_text: datetime_default
date_popup: datetime_default
media_generic: file_generic
phone_textfield: telephone_default
options_onoff: boolean_checkbox
entityreference_autocomplete: entity_reference_autocomplete
'options/settings':
plugin: field_instance_widget_settings
source:
- 'widget/type'
- widget_settings
'options/third_party_settings': 'constants/third_party_settings'
destination:
plugin: component_entity_form_display
migration_dependencies:
required:
- d7_field_instance
id: d7_view_modes
label: Drupal 7 view modes
migration_tags:
- Drupal 7
source:
plugin: d7_view_mode
process:
mode:
plugin: static_map
source: view_mode
bypass: true
map:
default: full
label:
plugin: static_map
source: view_mode
map:
search_index: "Search index"
search_result: "Search result"
rss: "RSS"
print: "Print"
teaser: "Teaser"
full: "Full"
default: "Full"
targetEntityType: entity_type
destination:
plugin: entity:entity_view_mode
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\process\d7\FieldInstanceDefaults.
*/
namespace Drupal\field\Plugin\migrate\process\d7;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* @MigrateProcessPlugin(
* id = "d7_field_instance_defaults"
* )
*/
class FieldInstanceDefaults extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($default_value, $widget_settings) = $value;
$widget_type = $widget_settings['type'];
$default = array();
foreach ($default_value as $item) {
switch ($widget_type) {
// Add special processing here if needed.
default:
$default[] = $item;
}
}
return $default;
}
}
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\process\d7\FieldInstanceSettings.
*/
namespace Drupal\field\Plugin\migrate\process\d7;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* @MigrateProcessPlugin(
* id = "d7_field_instance_settings"
* )
*/
class FieldInstanceSettings extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($instance_settings, $widget_settings) = $value;
$widget_type = $widget_settings['type'];
switch ($widget_type) {
case 'image_image':
$settings = $instance_settings;
$settings['default_image'] = array(
'alt' => '',
'title' => '',
'width' => NULL,
'height' => NULL,
'uuid' => '',
);
break;
default:
$settings = $instance_settings;
}
return $settings;
}
}
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\process\d7\FieldSettings.
*/
namespace Drupal\field\Plugin\migrate\process\d7;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* @MigrateProcessPlugin(
* id = "d7_field_settings"
* )
*/
class FieldSettings extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$value = $row->getSourceProperty('settings');
if ($row->getSourceProperty('type') == 'image' && !is_array($value['default_image'])) {
$value['default_image'] = array(
'uuid' => '',
);
}
return $value;
}
}
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\source\d7\Field.
*/
namespace Drupal\field\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 field source from database.
*
* @MigrateSource(
* id = "d7_field"
* )
*/
class Field extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('field_config', 'fc')
->fields('fc')
->fields('fci', array('entity_type'))
->condition('fc.active', 1)
->condition('fc.deleted', 0)
->condition('fc.storage_active', 1);
$query->join('field_config_instance', 'fci', 'fc.id = fci.field_id');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'field_name' => $this->t('The name of this field.'),
'type' => $this->t('The type of this field.'),
'module' => $this->t('The module that implements the field type.'),
'storage' => $this->t('The field storage.'),
'locked' => $this->t('Locked'),
'cardinality' => $this->t('Cardinality'),
'translatable' => $this->t('Translatable'),
);
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row, $keep = TRUE) {
foreach (unserialize($row->getSourceProperty('data')) as $key => $value) {
$row->setSourceProperty($key, $value);
}
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return array(
'field_name' => array(
'type' => 'string',
'alias' => 'fc',
),
'entity_type' => array(
'type' => 'string',
'alias' => 'fci',
),
);
}
}
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\source\d7\FieldInstance.
*/
namespace Drupal\field\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 field instances source from database.
*
* @MigrateSource(
* id = "d7_field_instance",
* )
*/
class FieldInstance extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('field_config_instance', 'fci')
->fields('fci')
->condition('fci.deleted', 0)
->condition('fc.active', 1)
->condition('fc.deleted', 0)
->condition('fc.storage_active', 1);
$query->innerJoin('field_config', 'fc', 'fci.field_id = fc.id');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'field_name' => $this->t('The machine name of field.'),
'entity_type' => $this->t('The entity type.'),
'bundle' => $this->t('The entity bundle.'),
'default_value' => $this->t('Default value'),
'instance_settings' => $this->t('Field instance settings.'),
'widget_settings' => $this->t('Widget settings.'),
'display_settings' => $this->t('Display settings.'),
);
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$data = unserialize($row->getSourceProperty('data'));
$row->setSourceProperty('label', $data['label']);
$row->setSourceProperty('description', $data['description']);
$row->setSourceProperty('required', $data['required']);
$default_value = !empty($data['default_value']) ? $data['default_value'] : array();
if ($data['widget']['type'] == 'email_textfield' && $default_value) {
$default_value[0]['value'] = $default_value[0]['email'];
unset($default_value[0]['email']);
}
$row->setSourceProperty('default_value', $default_value);
// Settings.
$row->setSourceProperty('instance_settings', $data['settings']);
$row->setSourceProperty('widget_settings', $data['widget']);
$row->setSourceProperty('display_settings', $data['display']);
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return array(
'entity_type' => array(
'type' => 'string',
'alias' => 'fci',
),
'bundle' => array(
'type' => 'string',
'alias' => 'fci',
),
'field_name' => array(
'type' => 'string',
'alias' => 'fci',
),
);
}
}
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\source\d7\FieldInstancePerFormDisplay.
*/
namespace Drupal\field\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* The field instance per form display source class.
*
* @MigrateSource(
* id = "d7_field_instance_per_form_display"
* )
*/
class FieldInstancePerFormDisplay extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('field_config_instance', 'fci')
->fields('fci', array(
'field_name',
'bundle',
'data',
'entity_type'
))
->fields('fc', array(
'type',
'module',
))
->condition('fci.entity_type','node');
$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 array(
'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.'),
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return array(
'bundle' => array(
'type' => 'string',
),
'field_name' => array(
'type' => 'string',
'alias' => 'fci',
),
);
}
}
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\source\d7\FieldInstancePerViewMode.
*/
namespace Drupal\field\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* The field instance per view mode source class.
*
* @MigrateSource(
* id = "d7_field_instance_per_view_mode",
* source_provider = "field"
* )
*/
class FieldInstancePerViewMode extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
$rows = array();
$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) {
$rows[] = array_merge($field_instance, $info, array('view_mode' => $view_mode));
}
}
return new \ArrayIterator($rows);
}
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('field_config_instance', 'fci')
->fields