Skip to content
Snippets Groups Projects
Commit f2585a01 authored by Angie Byron's avatar Angie Byron
Browse files

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
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Showing
with 1568 additions and 0 deletions
......@@ -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('fci', array('entity_type', 'bundle', 'field_name', 'data'));
}
/**
* {@inheritdoc}
*/
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.'),
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return array(
'entity_type' => array(
'type' => 'string',
),
'bundle' => array(
'type' => 'string',
),
'view_mode' => array(
'type' => 'string',
),
'field_name' => array(
'type' => 'string',
),
);
}
/**
* {@inheritdoc}
*/
public function count() {
return $this->initializeIterator()->count();
}
}
<?php
/**
* @file
* Contains \Drupal\field\Plugin\migrate\source\d7\ViewMode.
*/
namespace Drupal\field\Plugin\migrate\source\d7;
use Drupal\migrate\Annotation\MigrateSource;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* @MigrateSource(
* id = "d7_view_mode"
* )
*/
class ViewMode extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
$rows = [];
$result = $this->prepareQuery()->execute();
foreach ($result as $field_instance) {
$data = unserialize($field_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'],
'view_mode' => $view_mode,
];
}
}
return new \ArrayIterator($rows);
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'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']);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'entity_type' => [
'type' => 'string',
],
'view_mode' => [
'type' => 'string',
],
];
}
/**
* {@inheritdoc}
*/
public function count() {
return $this->initializeIterator()->count();
}
}
<?php
/**
* @file
* Contains \Drupal\field\Tests\Migrate\d7\MigrateFieldFormatterSettingsTest.
*/
namespace Drupal\field\Tests\Migrate\d7;
use Drupal\comment\Entity\CommentType;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
use Drupal\node\Entity\NodeType;
/**
* Tests migration of D7 field formatter settings.
*
* @group field
*/
class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
public static $modules = [
'comment',
'datetime',
'entity_reference',
'file',
'image',
'link',
'node',
'telephone',
'text',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('comment');
CommentType::create([
'id' => 'comment_node_page',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_article',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_blog',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_book',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_forum',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_test_content_type',
'label' => $this->randomMachineName(),
])->save();
$this->installEntitySchema('node');
NodeType::create([
'type' => 'page',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'article',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'blog',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'book',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'forum',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'test_content_type',
'label' => $this->randomMachineName(),
])->save();
$this->executeMigration('d7_field');
$this->executeMigration('d7_field_instance');
$this->executeMigration('d7_view_modes');
$this->executeMigration('d7_field_formatter_settings');
}
/**
* Asserts various aspects of a view display.
*
* @param string $id
* The view display ID.
*/
protected function assertEntity($id) {
$display = EntityViewDisplay::load($id);
$this->assertTrue($display instanceof EntityViewDisplayInterface);
}
/**
* Asserts various aspects of a particular component of a view display.
*
* @param string $display_id
* The view display ID.
* @param string $component_id
* The component ID.
* @param string $type
* The expected component type (formatter plugin ID).
* @param string $label
* The expected label of the component.
* @param int $weight
* The expected weight of the component.
*/
protected function assertComponent($display_id, $component_id, $type, $label, $weight) {
$component = EntityViewDisplay::load($display_id)->getComponent($component_id);
$this->assertTrue(is_array($component));
$this->assertIdentical($type, $component['type']);
$this->assertIdentical($label, $component['label']);
$this->assertIdentical($weight, $component['weight']);
}
/**
* Asserts that a particular component is NOT included in a display.
*
* @param string $display_id
* The display ID.
* @param string $component_id
* The component ID.
*/
protected function assertComponentNotExists($display_id, $component_id) {
$component = EntityViewDisplay::load($display_id)->getComponent($component_id);
$this->assertTrue(is_null($component));
}
/**
* Tests migration of D7 field formatter settings.
*/
public function testMigration() {
$this->assertEntity('comment.comment_node_article.default');
$this->assertComponent('comment.comment_node_article.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('comment.comment_node_blog.default');
$this->assertComponent('comment.comment_node_blog.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('comment.comment_node_book.default');
$this->assertComponent('comment.comment_node_book.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('comment.comment_node_forum.default');
$this->assertComponent('comment.comment_node_forum.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('comment.comment_node_page.default');
$this->assertComponent('comment.comment_node_page.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('comment.comment_node_test_content_type.default');
$this->assertComponent('comment.comment_node_test_content_type.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertComponent('comment.comment_node_test_content_type.default', 'field_integer', 'number_integer', 'above', 1);
$this->assertEntity('node.article.default');
$this->assertComponent('node.article.default', 'body', 'text_default', 'hidden', 0);
$this->assertComponent('node.article.default', 'field_tags', 'entity_reference_label', 'above', 10);
$this->assertComponent('node.article.default', 'field_image', 'image', 'hidden', -1);
$this->assertEntity('node.article.teaser');
$this->assertComponent('node.article.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
$this->assertComponent('node.article.teaser', 'field_tags', 'entity_reference_label', 'above', 10);
$this->assertComponent('node.article.teaser', 'field_image', 'image', 'hidden', -1);
$this->assertEntity('node.blog.default');
$this->assertComponent('node.blog.default', 'body', 'text_default', 'hidden', 0);
$this->assertEntity('node.blog.teaser');
$this->assertComponent('node.blog.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
$this->assertEntity('node.book.default');
$this->assertComponent('node.book.default', 'body', 'text_default', 'hidden', 0);
$this->assertEntity('node.book.teaser');
$this->assertComponent('node.book.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
$this->assertEntity('node.forum.default');
$this->assertComponent('node.forum.default', 'body', 'text_default', 'hidden', 11);
$this->assertComponent('node.forum.default', 'taxonomy_forums', 'entity_reference_label', 'above', 10);
$this->assertEntity('node.forum.teaser');
$this->assertComponent('node.forum.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 11);
$this->assertComponent('node.forum.teaser', 'taxonomy_forums', 'entity_reference_label', 'above', 10);
$this->assertEntity('node.page.default');
$this->assertComponent('node.page.default', 'body', 'text_default', 'hidden', 0);
$this->assertEntity('node.page.teaser');
$this->assertComponent('node.page.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
$this->assertEntity('node.test_content_type.default');
$this->assertComponent('node.test_content_type.default', 'field_boolean', 'list_default', 'above', 0);
$this->assertComponent('node.test_content_type.default', 'field_email', 'email_mailto', 'above', 1);
// Phone formatters are not mapped and should default to basic_string.
$this->assertComponent('node.test_content_type.default', 'field_phone', 'basic_string', 'above', 2);
$this->assertComponent('node.test_content_type.default', 'field_date', 'datetime_default', 'above', 3);
$this->assertComponent('node.test_content_type.default', 'field_date_with_end_time', 'datetime_default', 'above', 4);
$this->assertComponent('node.test_content_type.default', 'field_file', 'file_default', 'above', 5);
$this->assertComponent('node.test_content_type.default', 'field_float', 'number_decimal', 'above', 6);
$this->assertComponent('node.test_content_type.default', 'field_images', 'image', 'above', 7);
$this->assertComponent('node.test_content_type.default', 'field_integer', 'number_integer', 'above', 8);
$this->assertComponent('node.test_content_type.default', 'field_link', 'link', 'above', 9);
$this->assertComponent('node.test_content_type.default', 'field_text_list', 'list_default', 'above', 10);
$this->assertComponent('node.test_content_type.default', 'field_integer_list', 'list_default', 'above', 11);
$this->assertComponent('node.test_content_type.default', 'field_long_text', 'text_default', 'above', 12);
$this->assertComponentNotExists('node.test_content_type.default', 'field_term_reference');
$this->assertComponentNotExists('node.test_content_type.default', 'field_text');
$this->assertEntity('user.user.default');
$this->assertComponent('user.user.default', 'field_file', 'file_default', 'above', 0);
}
}
<?php
/**
* @file
* Contains \Drupal\field\Tests\Migrate\d7\MigrateFieldInstanceTest.
*/
namespace Drupal\field\Tests\Migrate\d7;
use Drupal\comment\Entity\CommentType;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldConfigInterface;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
use Drupal\node\Entity\NodeType;
/**
* Migrates Drupal 7 field instances.
*
* @group field
*/
class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array(
'comment',
'datetime',
'entity_reference',
'file',
'image',
'link',
'node',
'system',
'taxonomy',
'telephone',
'text',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->createType('page');
$this->createType('article');
$this->createType('blog');
$this->createType('book');
$this->createType('forum');
$this->createType('test_content_type');
$this->executeMigration('d7_field');
$this->executeMigration('d7_field_instance');
}
/**
* Creates a node type with a corresponding comment type.
*
* @param string $id
* The node type ID.
*/
protected function createType($id) {
NodeType::create(array(
'type' => $id,
'label' => $this->randomString(),
))->save();
CommentType::create(array(
'id' => 'comment_node_' . $id,
'label' => $this->randomString(),
'target_entity_type_id' => 'node',
))->save();
}
/**
* Asserts various aspects of a field config entity.
*
* @param string $id
* The entity ID in the form ENTITY_TYPE.BUNDLE.FIELD_NAME.
* @param string $expected_label
* The expected field label.
* @param string $expected_field_type
* The expected field type.
* @param boolean $is_required
* Whether or not the field is required.
*/
protected function assertEntity($id, $expected_label, $expected_field_type, $is_required) {
list ($expected_entity_type, $expected_bundle, $expected_name) = explode('.', $id);
/** @var \Drupal\field\FieldConfigInterface $field */
$field = FieldConfig::load($id);
$this->assertTrue($field instanceof FieldConfigInterface);
$this->assertIdentical($expected_label, $field->label());
$this->assertIdentical($expected_field_type, $field->getType());
$this->assertIdentical($expected_entity_type, $field->getTargetEntityTypeId());
$this->assertIdentical($expected_bundle, $field->getTargetBundle());
$this->assertIdentical($expected_name, $field->getName());
$this->assertEqual($is_required, $field->isRequired());
$this->assertIdentical($expected_entity_type . '.' . $expected_name, $field->getFieldStorageDefinition()->id());
}
/**
* Tests migrating D7 field instances to field_config entities.
*/
public function testFieldInstances() {
$this->assertEntity('comment.comment_node_page.comment_body', 'Comment', 'text_long', TRUE);
$this->assertEntity('node.page.body', 'Body', 'text_with_summary', FALSE);
$this->assertEntity('comment.comment_node_article.comment_body', 'Comment', 'text_long', TRUE);
$this->assertEntity('node.article.body', 'Body', 'text_with_summary', FALSE);
$this->assertEntity('node.article.field_tags', 'Tags', 'entity_reference', FALSE);
$this->assertEntity('node.article.field_image', 'Image', 'image', FALSE);
$this->assertEntity('comment.comment_node_blog.comment_body', 'Comment', 'text_long', TRUE);
$this->assertEntity('node.blog.body', 'Body', 'text_with_summary', FALSE);
$this->assertEntity('comment.comment_node_book.comment_body', 'Comment', 'text_long', TRUE);
$this->assertEntity('node.book.body', 'Body', 'text_with_summary', FALSE);
$this->assertEntity('node.forum.taxonomy_forums', 'Forums', 'entity_reference', TRUE);
$this->assertEntity('comment.comment_node_forum.comment_body', 'Comment', 'text_long', TRUE);
$this->assertEntity('node.forum.body', 'Body', 'text_with_summary', FALSE);
$this->assertEntity('comment.comment_node_test_content_type.comment_body', 'Comment', 'text_long', TRUE);
$this->assertEntity('node.test_content_type.field_boolean', 'Boolean', 'boolean', FALSE);
$this->assertEntity('node.test_content_type.field_email', 'Email', 'email', FALSE);
$this->assertEntity('node.test_content_type.field_phone', 'Phone', 'telephone', TRUE);
$this->assertEntity('node.test_content_type.field_date', 'Date', 'datetime', FALSE);
$this->assertEntity('node.test_content_type.field_date_with_end_time', 'Date With End Time', 'datetime', FALSE);
$this->assertEntity('node.test_content_type.field_file', 'File', 'file', FALSE);
$this->assertEntity('node.test_content_type.field_float', 'Float', 'float', FALSE);
$this->assertEntity('node.test_content_type.field_images', 'Images', 'image', TRUE);
$this->assertEntity('node.test_content_type.field_integer', 'Integer', 'integer', TRUE);
$this->assertEntity('node.test_content_type.field_link', 'Link', 'link', FALSE);
$this->assertEntity('node.test_content_type.field_text_list', 'Text List', 'list_string', FALSE);
$this->assertEntity('node.test_content_type.field_integer_list', 'Integer List', 'list_integer', FALSE);
$this->assertEntity('node.test_content_type.field_long_text', 'Long text', 'text_with_summary', FALSE);
$this->assertEntity('node.test_content_type.field_term_reference', 'Term Reference', 'entity_reference', FALSE);
$this->assertEntity('node.test_content_type.field_text', 'Text', 'text', FALSE);
$this->assertEntity('comment.comment_node_test_content_type.field_integer', 'Integer', 'integer', FALSE);
$this->assertEntity('user.user.field_file', 'File', 'file', FALSE);
}
}
<?php
/**
* @file
* Contains \Drupal\field\Tests\Migrate\d7\MigrateFieldInstanceWidgetSettingsTest.
*/
namespace Drupal\field\Tests\Migrate\d7;
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
use Drupal\node\Entity\NodeType;
/**
* Migrate field widget settings.
*
* @group field
*/
class MigrateFieldInstanceWidgetSettingsTest extends MigrateDrupal7TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array(
'field',
'telephone',
'link',
'file',
'image',
'datetime',
'node',
'text',
);
/**
* Creates a node type.
*
* @param string $id
* The node type ID.
*/
protected function createNodeType($id) {
NodeType::create(array(
'type' => $id,
'label' => $this->randomString(),
))->save();
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->createNodeType('page');
$this->createNodeType('article');
$this->createNodeType('blog');
$this->createNodeType('book');
$this->createNodeType('forum');
$this->createNodeType('test_content_type');
// Add some id mappings for the dependent migrations.
$id_mappings = [
'd7_field' => [
[['comment', 'comment_body'], ['comment', 'comment_body']],
[['node', 'body'], ['node', 'body']],
[['node', 'field_tags'], ['node', 'field_tags']],
[['node', 'field_image'], ['node', 'field_image']],
[['node', 'taxonomy_forums'], ['node', 'taxonomy_forums']],
[['node', 'field_boolean'], ['node', 'field_boolean']],
[['node', 'field_email'], ['node', 'field_email']],
[['node', 'field_phone'], ['node', 'field_phone']],
[['node', 'field_date'], ['node', 'field_date']],
[['node', 'field_date_with_end_time'], ['node', 'field_date_with_end_time']],
[['node', 'field_file'], ['node', 'field_file']],
[['node', 'field_float'], ['node', 'field_float']],
[['node', 'field_images'], ['node', 'field_images']],
[['node', 'field_integer'], ['node', 'field_integer']],
[['node', 'field_link'], ['node', 'field_link']],
[['node', 'field_text_list'], ['node', 'field_text_list']],
[['node', 'field_integer_list'], ['node', 'field_integer_list']],
[['node', 'field_long_text'], ['node', 'field_long_text']],
[['node', 'field_term_reference'], ['node', 'field_term_reference']],
[['node', 'field_text'], ['node', 'field_text']],
[['node', 'field_integer'], ['node', 'field_integer']],
[['user', 'field_file'], ['user', 'field_file']],
],
// We don't actually need any ID lookups from the d7_field_instance
// migration -- it's merely a sensible dependency.
'd7_field_instance' => [],
];
$this->prepareMigrations($id_mappings);
$this->executeMigration('d7_field_instance_widget_settings');
}
/**
* Asserts various aspects of a form display entity.
*
* @param string $id
* The entity ID.
* @param string $expected_entity_type
* The expected entity type to which the display settings are attached.
* @param string $expected_bundle
* The expected bundle to which the display settings are attached.
*/
protected function assertEntity($id, $expected_entity_type, $expected_bundle) {
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $entity */
$entity = EntityFormDisplay::load($id);
$this->assertTrue($entity instanceof EntityFormDisplayInterface);
$this->assertIdentical($expected_entity_type, $entity->getTargetEntityTypeId());
$this->assertIdentical($expected_bundle, $entity->getTargetBundle());
}
/**
* Asserts various aspects of a particular component of a form display.
*
* @param string $display_id
* The form display ID.
* @param string $component_id
* The component ID.
* @param string $widget_type
* The expected widget type.
* @param string $weight
* The expected weight of the component.
*/
protected function assertComponent($display_id, $component_id, $widget_type, $weight) {
$component = EntityFormDisplay::load($display_id)->getComponent($component_id);
$this->assertTrue(is_array($component));
$this->assertIdentical($widget_type, $component['type']);
$this->assertIdentical($weight, $component['weight']);
}
/**
* Test that migrated view modes can be loaded using D8 APIs.
*/
public function testWidgetSettings() {
$this->assertEntity('node.page.default', 'node', 'page');
$this->assertComponent('node.page.default', 'body', 'text_textarea_with_summary', -4);
$this->assertEntity('node.article.default', 'node', 'article');
$this->assertComponent('node.article.default', 'body', 'text_textarea_with_summary', -4);
$this->assertComponent('node.article.default', 'field_tags', 'taxonomy_autocomplete', -4);
$this->assertComponent('node.article.default', 'field_image', 'image_image', -1);
$this->assertEntity('node.blog.default', 'node', 'blog');
$this->assertComponent('node.blog.default', 'body', 'text_textarea_with_summary', -4);
$this->assertEntity('node.book.default', 'node', 'book');
$this->assertComponent('node.book.default', 'body', 'text_textarea_with_summary', -4);
$this->assertEntity('node.forum.default', 'node', 'forum');
$this->assertComponent('node.forum.default', 'body', 'text_textarea_with_summary', 1);
$this->assertComponent('node.forum.default', 'taxonomy_forums', 'options_select', 0);
$this->assertEntity('node.test_content_type.default', 'node', 'test_content_type');
$this->assertComponent('node.test_content_type.default', 'field_boolean', 'boolean_checkbox', 1);
$this->assertComponent('node.test_content_type.default', 'field_date', 'datetime_default', 2);
$this->assertComponent('node.test_content_type.default', 'field_date_with_end_time', 'datetime_default', 3);
$this->assertComponent('node.test_content_type.default', 'field_email', 'email_default', 4);
$this->assertComponent('node.test_content_type.default', 'field_file', 'file_generic', 5);
$this->assertComponent('node.test_content_type.default', 'field_float', 'number', 7);
$this->assertComponent('node.test_content_type.default', 'field_images', 'image_image', 8);
$this->assertComponent('node.test_content_type.default', 'field_integer', 'number', 9);
$this->assertComponent('node.test_content_type.default', 'field_link', 'link_default', 10);
$this->assertComponent('node.test_content_type.default', 'field_integer_list', 'options_buttons', 12);
$this->assertComponent('node.test_content_type.default', 'field_long_text', 'text_textarea_with_summary', 13);
$this->assertComponent('node.test_content_type.default', 'field_phone', 'telephone_default', 6);
$this->assertComponent('node.test_content_type.default', 'field_term_reference', 'taxonomy_autocomplete', 14);
$this->assertComponent('node.test_content_type.default', 'field_text', 'text_textfield', 15);
$this->assertComponent('node.test_content_type.default', 'field_text_list', 'options_select', 11);
}
}
<?php
/**
* @file
* Contains \Drupal\field\Tests\Migrate\d7\MigrateFieldTest.
*/
namespace Drupal\field\Tests\Migrate\d7;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Migrates Drupal 7 fields.
*
* @group field
*/
class MigrateFieldTest extends MigrateDrupal7TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array(
'comment',
'datetime',
'entity_reference',
'file',
'image',
'link',
'node',
'system',
'taxonomy',
'telephone',
'text',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->executeMigration('d7_field');
}
/**
* Asserts various aspects of a field_storage_config entity.
*
* @param string $id
* The entity ID in the form ENTITY_TYPE.FIELD_NAME.
* @param string $expected_type
* The expected field type.
* @param boolean $expected_translatable
* Whether or not the field is expected to be translatable.
* @param integer $expected_cardinality
* The expected cardinality of the field.
*/
protected function assertEntity($id, $expected_type, $expected_translatable, $expected_cardinality) {
list ($expected_entity_type, $expected_name) = explode('.', $id);
/** @var \Drupal\field\FieldStorageConfigInterface $field */
$field = FieldStorageConfig::load($id);
$this->assertTrue($field instanceof FieldStorageConfigInterface);
$this->assertIdentical($expected_name, $field->getName());
$this->assertIdentical($expected_type, $field->getType());
// FieldStorageConfig::$translatable is TRUE by default, so it is useful
// to test for FALSE here.
$this->assertEqual($expected_translatable, $field->isTranslatable());
$this->assertIdentical($expected_entity_type, $field->getTargetEntityTypeId());
if ($expected_cardinality === 1) {
$this->assertFalse($field->isMultiple());
}
else {
$this->assertTrue($field->isMultiple());
}
$this->assertIdentical($expected_cardinality, $field->getCardinality());
}
/**
* Tests migrating D7 fields to field_storage_config entities.
*/
public function testFields() {
$this->assertEntity('node.body', 'text_with_summary', FALSE, 1);
$this->assertEntity('node.field_long_text', 'text_with_summary', FALSE, 1);
$this->assertEntity('comment.comment_body', 'text_long', FALSE, 1);
$this->assertEntity('node.field_file', 'file', FALSE, 1);
$this->assertEntity('user.field_file', 'file', FALSE, 1);
$this->assertEntity('node.field_float', 'float', FALSE, 1);
$this->assertEntity('node.field_image', 'image', FALSE, 1);
$this->assertEntity('node.field_images', 'image', FALSE, 1);
$this->assertEntity('node.field_integer', 'integer', FALSE, 1);
$this->assertEntity('comment.field_integer', 'integer', FALSE, 1);
$this->assertEntity('node.field_integer_list', 'list_integer', FALSE, 1);
$this->assertEntity('node.field_link', 'link', FALSE, 1);
$this->assertEntity('node.field_tags', 'entity_reference', FALSE, -1);
$this->assertEntity('node.field_term_reference', 'entity_reference', FALSE, 1);
$this->assertEntity('node.taxonomy_forums', 'entity_reference', FALSE, 1);
$this->assertEntity('node.field_text', 'text', FALSE, 1);
$this->assertEntity('node.field_text_list', 'list_string', FALSE, 3);
$this->assertEntity('node.field_boolean', 'boolean', FALSE, 1);
$this->assertEntity('node.field_email', 'email', FALSE, -1);
$this->assertEntity('node.field_phone', 'telephone', FALSE, 1);
$this->assertEntity('node.field_date', 'datetime', FALSE, 1);
$this->assertEntity('node.field_date_with_end_time', 'datetime', FALSE, 1);
}
}
<?php
/**
* @file
* Contains \Drupal\field\Tests\Migrate\d7\MigrateViewModesTest.
*/
namespace Drupal\field\Tests\Migrate\d7;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\Core\Entity\EntityViewModeInterface;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Tests migration of D7 view modes.
*
* @group field
*/
class MigrateViewModesTest extends MigrateDrupal7TestBase {
public static $modules = ['comment', 'node'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('comment');
$this->installEntitySchema('node');
$this->executeMigration('d7_view_modes');
}
/**
* Asserts various aspects of a view mode entity.
*
* @param string $id
* The entity ID.
* @param string $label
* The expected label of the view mode.
* @param string $entity_type
* The expected entity type ID which owns the view mode.
* @param bool $status
* The expected status of the view mode.
*/
protected function assertEntity($id, $label, $entity_type) {
/** @var \Drupal\Core\Entity\EntityViewModeInterface $view_mode */
$view_mode = EntityViewMode::load($id);
$this->assertTrue($view_mode instanceof EntityViewModeInterface);
$this->assertIdentical($label, $view_mode->label());
$this->assertIdentical($entity_type, $view_mode->getTargetType());
}
/**
* Tests migration of D7 view mode variables to D8 config entities.
*/
public function testMigration() {
$this->assertEntity('comment.full', 'Full', 'comment');
$this->assertEntity('node.teaser', 'Teaser', 'node');
$this->assertEntity('node.full', 'Full', 'node');
$this->assertEntity('user.full', 'Full', 'user');
}
}
<?php
/**
* @file
* Contains \Drupal\Tests\field\Unit\Plugin\migrate\process\d7\FieldInstanceSettingsTest.
*/
namespace Drupal\Tests\field\Unit\Plugin\migrate\process\d7;
use Drupal\field\Plugin\migrate\process\d7\FieldInstanceSettings;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Drupal\Tests\migrate\Unit\MigrateTestCase;
/**
* @coversDefaultClass \Drupal\field\Plugin\migrate\process\d7\FieldInstanceSettings
* @group field
*/
class FieldInstanceSettingsTest extends MigrateTestCase {
/**
* Tests transformation of image field settings.
*
* @covers ::transform
*/
public function testTransformImageSettings() {
$migration = $this->getMock(MigrationInterface::class);
$plugin = new FieldInstanceSettings([], 'd7_field_instance_settings', [], $migration);
$executable = $this->getMock(MigrateExecutableInterface::class);
$row = $this->getMockBuilder(Row::class)
->disableOriginalConstructor()
->getMock();
$value = $plugin->transform([[], ['type' => 'image_image']], $executable, $row, 'foo');
$this->assertInternalType('array', $value['default_image']);
$this->assertSame('', $value['default_image']['alt']);
$this->assertSame('', $value['default_image']['title']);
$this->assertNull($value['default_image']['width']);
$this->assertNull($value['default_image']['height']);
$this->assertSame('', $value['default_image']['uuid']);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment