Issue #2262275 by hussainweb, hosef, ultimike: Fixed D6->D8 CCK Single On/Off Checkbox, Checkboxes/Radio buttons, and Select formatters.

8.0.x
Alex Pott 2014-07-31 16:22:34 +01:00
parent 7420742b62
commit 267202b248
8 changed files with 372 additions and 100 deletions

View File

@ -15,53 +15,108 @@ process:
type:
-
plugin: static_map
bypass: true
source:
- type
- widget_type
map:
number_integer: integer
number_decimal: decimal
number_float: float
text: text
email: email
link: link
date: datetime
datestamp: datetime
datetime: datetime
fr_phone: telephone
be_phone: telephone
it_phone: telephone
el_phone: telephone
ch_phone: telephone
ca_phone: telephone
cr_phone: telephone
pa_phone: telephone
gb_phone: telephone
ru_phone: telephone
ua_phone: telephone
es_phone: telephone
au_phone: telephone
cs_phone: telephone
hu_phone: telephone
pl_phone: telephone
nl_phone: telephone
se_phone: telephone
za_phone: telephone
il_phone: telephone
nz_phone: telephone
br_phone: telephone
cl_phone: telephone
cn_phone: telephone
hk_phone: telephone
mo_phone: telephone
ph_phone: telephone
sg_phone: telephone
jo_phone: telephone
eg_phone: telephone
pk_phone: telephone
int_phone: telephone
-
plugin: file_image_handler
number_integer:
number: integer
optionwidgets_select: list_integer
optionwidgets_buttons: list_integer
optionwidgets_onoff: boolean
number_decimal:
number: decimal
optionwidgets_select: list_float
optionwidgets_buttons: list_float
optionwidgets_onoff: boolean
number_float:
number: float
optionwidgets_select: list_float
optionwidgets_buttons: list_float
optionwidgets_onoff: boolean
text:
optionwidgets_select: list_text
optionwidgets_buttons: list_text
optionwidgets_onoff: boolean
text_textfield: text
text_textarea: text_long
email:
email_textfield: email
link:
link: link
filefield:
imagefield_widget: image
filefield_widget: file
date:
date_select: datetime
datestamp:
date_select: datetime
datetime:
date_select: datetime
fr_phone:
phone_textfield: telephone
be_phone:
phone_textfield: telephone
it_phone:
phone_textfield: telephone
el_phone:
phone_textfield: telephone
ch_phone:
phone_textfield: telephone
ca_phone:
phone_textfield: telephone
cr_phone:
phone_textfield: telephone
pa_phone:
phone_textfield: telephone
gb_phone:
phone_textfield: telephone
ru_phone:
phone_textfield: telephone
ua_phone:
phone_textfield: telephone
es_phone:
phone_textfield: telephone
au_phone:
phone_textfield: telephone
cs_phone:
phone_textfield: telephone
hu_phone:
phone_textfield: telephone
pl_phone:
phone_textfield: telephone
nl_phone:
phone_textfield: telephone
se_phone:
phone_textfield: telephone
za_phone:
phone_textfield: telephone
il_phone:
phone_textfield: telephone
nz_phone:
phone_textfield: telephone
br_phone:
phone_textfield: telephone
cl_phone:
phone_textfield: telephone
cn_phone:
phone_textfield: telephone
hk_phone:
phone_textfield: telephone
mo_phone:
phone_textfield: telephone
ph_phone:
phone_textfield: telephone
sg_phone:
phone_textfield: telephone
jo_phone:
phone_textfield: telephone
eg_phone:
phone_textfield: telephone
pk_phone:
phone_textfield: telephone
int_phone:
phone_textfield: telephone
cardinality:
plugin: static_map
bypass: true

View File

@ -49,6 +49,7 @@ process:
text:
default: text_default
trimmed: text_trimmed
plain: string
number_integer:
default: number_integer
us_0: number_integer

View File

@ -48,6 +48,27 @@ class FieldSettings extends ProcessPluginBase {
$title_label = isset($widget_settings['title']) ? $widget_settings['title'] : '';
$max_length = isset($global_settings['max_length']) ? $global_settings['max_length'] : '';
$max_length = empty($max_length) ? 255 : $max_length;
if (isset($global_settings['allowed_values'])) {
$list = explode("\n", $global_settings['allowed_values']);
$list = array_map('trim', $list);
$list = array_filter($list, 'strlen');
switch ($field_type) {
case 'list_text':
case 'list_integer':
case 'list_float':
foreach ($list as $value) {
$value = explode("|", $value);
$allowed_values[$value[0]] = isset($value[1]) ? $value[1] : $value[0];
}
break;
default:
$allowed_values = $list;
}
}
else {
$allowed_values = '';
}
$settings = array(
'text' => array(
@ -60,6 +81,18 @@ class FieldSettings extends ProcessPluginBase {
),
),
'datetime' => array('datetime_type' => 'datetime'),
'list_text' => array(
'allowed_values' => $allowed_values,
),
'list_integer' => array(
'allowed_values' => $allowed_values,
),
'list_float' => array(
'allowed_values' => $allowed_values,
),
'boolean' => array(
'allowed_values' => $allowed_values,
),
);
return isset($settings[$field_type]) ? $settings[$field_type] : array();

View File

@ -1,46 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Plugin\migrate\Process\d6\system_update_7000.
*/
namespace Drupal\migrate_drupal\Plugin\migrate\process\d6;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* Decide if it's an image or a file when coming from a D6 filefield.
*
* @MigrateProcessPlugin(
* id = "file_image_handler"
* )
*/
class FileImageHandler extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
// If it's an array then the map missed.
if (is_array($value)) {
// Filefields in D6 have no way to tell if it's an image or file so we
// have to look at the widget type as well.
if ($row->getSourceProperty('module') == 'filefield') {
$widget_type = $row->getSourceProperty('widget_type');
$value = $widget_type == "imagefield_widget" ? "image" : "file";
}
else {
throw new MigrateSkipRowException();
}
}
return $value;
}
}

View File

@ -626,6 +626,134 @@ class Drupal6FieldInstance extends Drupal6DumpBase {
)),
'description' => 'An example datetime field.',
))
->values(array(
'field_name' => 'field_test_decimal_radio_buttons',
'type_name' => 'story',
'weight' => 13,
'label' => 'Decimal Radio Buttons Field',
'widget_type' => 'optionwidgets_buttons',
'widget_settings' => 'a:2:{s:13:"default_value";a:1:{i:0;a:1:{s:5:"value";s:0:"";}}s:17:"default_value_php";N;}',
'display_settings' => serialize(array(
'weight' => 13,
'parent' => '',
'label' => array(
'format' => 'above',
),
'teaser' => array(
'format' => 'unformatted',
'exclude' => 0,
),
'full' => array(
'format' => 'us_0',
'exclude' => 0,
),
4 => array(
'format' => 'unformatted',
'exclude' => 0,
),
5 => array(
'format' => 'default',
'exclude' => 1,
),
)),
'description' => 'An example decimal field using radio buttons.',
))
->values(array(
'field_name' => 'field_test_float_single_checkbox',
'type_name' => 'story',
'weight' => 14,
'label' => 'Float Single Checkbox Field',
'widget_type' => 'optionwidgets_onoff',
'widget_settings' => 'a:2:{s:13:"default_value";a:1:{i:0;a:1:{s:5:"value";N;}}s:17:"default_value_php";N;}',
'display_settings' => serialize(array(
'weight' => 14,
'parent' => '',
'label' => array(
'format' => 'above',
),
'teaser' => array(
'format' => 'unformatted',
'exclude' => 0,
),
'full' => array(
'format' => 'us_0',
'exclude' => 0,
),
4 => array(
'format' => 'unformatted',
'exclude' => 0,
),
5 => array(
'format' => 'default',
'exclude' => 1,
),
)),
'description' => 'An example float field using a single on/off checkbox.',
))
->values(array(
'field_name' => 'field_test_integer_selectlist',
'type_name' => 'story',
'weight' => 15,
'label' => 'Integer Select List Field',
'widget_type' => 'optionwidgets_select',
'widget_settings' => 'a:2:{s:13:"default_value";a:1:{i:0;a:1:{s:5:"value";s:0:"";}}s:17:"default_value_php";N;}',
'display_settings' => serialize(array(
'weight' => 15,
'parent' => '',
'label' => array(
'format' => 'above',
),
'teaser' => array(
'format' => 'unformatted',
'exclude' => 0,
),
'full' => array(
'format' => 'us_0',
'exclude' => 0,
),
4 => array(
'format' => 'unformatted',
'exclude' => 0,
),
5 => array(
'format' => 'default',
'exclude' => 1,
),
)),
'description' => 'An example integer field using a select list.',
))
->values(array(
'field_name' => 'field_test_text_single_checkbox',
'type_name' => 'story',
'weight' => 16,
'label' => 'Text Single Checkbox Field',
'widget_type' => 'optionwidgets_onoff',
'widget_settings' => 'a:2:{s:13:"default_value";a:1:{i:0;a:1:{s:5:"value";N;}}s:17:"default_value_php";N;}',
'display_settings' => serialize(array(
'weight' => 16,
'parent' => '',
'label' => array(
'format' => 'above',
),
'teaser' => array(
'format' => 'trimmed',
'exclude' => 0,
),
'full' => array(
'format' => 'default',
'exclude' => 0,
),
4 => array(
'format' => 'trimmed',
'exclude' => 0,
),
5 => array(
'format' => 'default',
'exclude' => 1,
),
)),
'description' => 'An example text field using a single on/off checkbox.',
))
->execute();
// Create the field table.
@ -856,6 +984,58 @@ class Drupal6FieldInstance extends Drupal6DumpBase {
'db_columns' => 'a:0:{}',
'active' => 0,
))
->values(array(
'field_name' => 'field_test_decimal_radio_buttons',
'module' => 'number',
'type' => 'number_decimal',
'global_settings' => 'a:9:{s:6:"prefix";s:0:"";s:6:"suffix";s:0:"";s:3:"min";s:0:"";s:3:"max";s:0:"";s:14:"allowed_values";s:7:"1.2
2.1";s:18:"allowed_values_php";s:0:"";s:9:"precision";s:2:"10";s:5:"scale";s:1:"2";s:7:"decimal";s:1:".";}',
'multiple' => 0,
'db_storage' => 1,
'db_columns' => 'a:0:{}',
'active' => 1,
))
->values(array(
'field_name' => 'field_test_float_single_checkbox',
'module' => 'number',
'type' => 'number_float',
'global_settings' => 'a:6:{s:6:"prefix";s:0:"";s:6:"suffix";s:0:"";s:3:"min";s:0:"";s:3:"max";s:0:"";s:14:"allowed_values";s:11:"3.142
1.234";s:18:"allowed_values_php";s:0:"";}',
'multiple' => 0,
'db_storage' => 1,
'db_columns' => 'a:0:{}',
'active' => 1,
))
->values(array(
'field_name' => 'field_test_integer_selectlist',
'module' => 'number',
'type' => 'number_integer',
'global_settings' => 'a:6:{s:6:"prefix";s:0:"";s:6:"suffix";s:0:"";s:3:"min";s:0:"";s:3:"max";s:0:"";s:14:"allowed_values";s:19:"1234
2341
3412
4123";s:18:"allowed_values_php";s:0:"";}',
'multiple' => 0,
'db_storage' => 1,
'db_columns' => serialize(array(
'value' => array(
'type' => 'int',
'not null' => FALSE,
'sortable' => TRUE,
),
)),
'active' => 1,
))
->values(array(
'field_name' => 'field_test_text_single_checkbox',
'module' => 'text',
'type' => 'text',
'global_settings' => 'a:4:{s:15:"text_processing";s:1:"0";s:10:"max_length";s:0:"";s:14:"allowed_values";s:13:"Hello
Goodbye";s:18:"allowed_values_php";s:0:"";}',
'multiple' => 0,
'db_storage' => 1,
'db_columns' => 'a:0:{}',
'active' => 1,
))
->execute();
$this->createTable('content_field_test', array(

View File

@ -310,6 +310,12 @@ class Drupal6Node extends Drupal6DumpBase {
'scale' => 2,
'not null' => FALSE
),
'field_test_integer_selectlist_value' => array(
'description' => 'Test integer select field column.',
'type' => 'int',
'unsigned' => FALSE,
'not null' => FALSE
),
),
'primary key' => array('vid'),
));
@ -319,11 +325,13 @@ class Drupal6Node extends Drupal6DumpBase {
'nid',
'vid',
'field_test_three_value',
'field_test_integer_selectlist_value',
))
->values(array(
'nid' => 1,
'vid' => 1,
'field_test_three_value' => '42.42',
'field_test_integer_selectlist_value' => '3412',
))
->execute();
$this->setModuleVersion('content', 6001);

View File

@ -8,6 +8,7 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\migrate\MigrateExecutable;
use Drupal\node\Entity\Node;
/**
* CCK field content migration.
@ -59,6 +60,16 @@ class MigrateCckFieldValuesTest extends MigrateNodeTestBase {
'field_name' => 'field_test_three',
'bundle' => 'story',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'name' => 'field_test_integer_selectlist',
'type' => 'integer',
))->save();
entity_create('field_instance_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_integer_selectlist',
'bundle' => 'story',
))->save();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
@ -87,12 +98,13 @@ class MigrateCckFieldValuesTest extends MigrateNodeTestBase {
* Test CCK migration from Drupal 6 to 8.
*/
public function testCckFields() {
$node = node_load(1);
$node = Node::load(1);
$this->assertEqual($node->field_test->value, 'This is a shared text field', "Shared field storage field is correct.");
$this->assertEqual($node->field_test->format, 1, "Shared field storage field with multiple columns is correct.");
$this->assertEqual($node->field_test_two->value, 10, 'Multi field storage field is correct');
$this->assertEqual($node->field_test_two[1]->value, 20, 'Multi field second value is correct.');
$this->assertEqual($node->field_test_three->value, '42.42', 'Single field second value is correct.');
$this->assertEqual($node->field_test_integer_selectlist[0]->value, '3412', 'Integer select list value is correct');
}
}

View File

@ -22,7 +22,7 @@ class MigrateFieldTest extends MigrateDrupalTestBase {
*
* @var array
*/
public static $modules = array('field', 'telephone', 'link', 'file', 'image', 'datetime', 'node');
public static $modules = array('field', 'telephone', 'link', 'file', 'image', 'datetime', 'node', 'options');
/**
* {@inheritdoc}
@ -47,28 +47,28 @@ class MigrateFieldTest extends MigrateDrupalTestBase {
/** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
$field_storage = entity_load('field_storage_config', 'node.field_test');
$expected = array('max_length' => 255);
$this->assertEqual($field_storage->type, "text", "Field type is text.");
$this->assertEqual($field_storage->type, "text", t('Field type is @fieldtype. It should be text.', array('@fieldtype' => $field_storage->type)));
$this->assertEqual($field_storage->status(), TRUE, "Status is TRUE");
$this->assertEqual($field_storage->settings, $expected, "Field type text settings are correct");
// Integer field.
$field_storage = entity_load('field_storage_config', 'node.field_test_two');
$this->assertEqual($field_storage->type, "integer", "Field type is integer.");
$this->assertEqual($field_storage->type, "integer", t('Field type is @fieldtype. It should be integer.', array('@fieldtype' => $field_storage->type)));
// Float field.
$field_storage = entity_load('field_storage_config', 'node.field_test_three');
$this->assertEqual($field_storage->type, "decimal", "Field type is decimal.");
$this->assertEqual($field_storage->type, "decimal", t('Field type is @fieldtype. It should be decimal.', array('@fieldtype' => $field_storage->type)));
// Link field.
$field_storage = entity_load('field_storage_config', 'node.field_test_link');
$this->assertEqual($field_storage->type, "link", "Field type is link.");
$this->assertEqual($field_storage->type, "link", t('Field type is @fieldtype. It should be link.', array('@fieldtype' => $field_storage->type)));
// File field.
$field_storage = entity_load('field_storage_config', 'node.field_test_filefield');
$this->assertEqual($field_storage->type, "file", "Field type is file.");
$this->assertEqual($field_storage->type, "file", t('Field type is @fieldtype. It should be file.', array('@fieldtype' => $field_storage->type)));
$field_storage = entity_load('field_storage_config', 'node.field_test_imagefield');
$this->assertEqual($field_storage->type, "image", "Field type is image.");
$this->assertEqual($field_storage->type, "image", t('Field type is @fieldtype. It should be image.', array('@fieldtype' => $field_storage->type)));
$settings = $field_storage->getSettings();
$this->assertEqual($settings['column_groups']['alt']['label'], 'Test alt');
$this->assertEqual($settings['column_groups']['title']['label'], 'Test title');
@ -79,12 +79,41 @@ class MigrateFieldTest extends MigrateDrupalTestBase {
// Phone field.
$field_storage = entity_load('field_storage_config', 'node.field_test_phone');
$this->assertEqual($field_storage->type, "telephone", "Field type is telephone.");
$this->assertEqual($field_storage->type, "telephone", t('Field type is @fieldtype. It should be telephone.', array('@fieldtype' => $field_storage->type)));
// Date field.
$field_storage = entity_load('field_storage_config', 'node.field_test_datetime');
$this->assertEqual($field_storage->type, "datetime", "Field type is datetime.");
$this->assertEqual($field_storage->type, "datetime", t('Field type is @fieldtype. It should be datetime.', array('@fieldtype' => $field_storage->type)));
$this->assertEqual($field_storage->status(), FALSE, "Status is FALSE");
// Decimal field with radio buttons.
$field_storage = entity_load('field_storage_config', 'node.field_test_decimal_radio_buttons');
$this->assertEqual($field_storage->type, "list_float", t('Field type is @fieldtype. It should be list_float.', array('@fieldtype' => $field_storage->type)));
$this->assertNotNull($field_storage->settings['allowed_values']['1.2'], t('First allowed value key is set to 1.2'));
$this->assertNotNull($field_storage->settings['allowed_values']['2.1'], t('Second allowed value key is set to 2.1'));
$this->assertEqual($field_storage->settings['allowed_values']['1.2'], '1.2', t('First allowed value is set to 1.2'));
$this->assertEqual($field_storage->settings['allowed_values']['2.1'], '2.1', t('Second allowed value is set to 1.2'));
// Float field with a single checkbox.
$field_storage = entity_load('field_storage_config', 'node.field_test_float_single_checkbox');
$this->assertEqual($field_storage->type, "boolean", t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->type)));
// Integer field with a select list.
$field_storage = entity_load('field_storage_config', 'node.field_test_integer_selectlist');
$this->assertEqual($field_storage->type, "list_integer", t('Field type is @fieldtype. It should be list_integer.', array('@fieldtype' => $field_storage->type)));
$this->assertNotNull($field_storage->settings['allowed_values']['1234'], t('First allowed value key is set to 1234'));
$this->assertNotNull($field_storage->settings['allowed_values']['2341'], t('Second allowed value key is set to 2341'));
$this->assertNotNull($field_storage->settings['allowed_values']['3412'], t('Third allowed value key is set to 3412'));
$this->assertNotNull($field_storage->settings['allowed_values']['4123'], t('Fourth allowed value key is set to 4123'));
$this->assertEqual($field_storage->settings['allowed_values']['1234'], '1234', t('First allowed value is set to 1234'));
$this->assertEqual($field_storage->settings['allowed_values']['2341'], '2341', t('Second allowed value is set to 2341'));
$this->assertEqual($field_storage->settings['allowed_values']['3412'], '3412', t('Third allowed value is set to 3412'));
$this->assertEqual($field_storage->settings['allowed_values']['4123'], '4123', t('Fourth allowed value is set to 4123'));
// Text field with a single checkbox.
$field_storage = entity_load('field_storage_config', 'node.field_test_text_single_checkbox');
$this->assertEqual($field_storage->type, "boolean", t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->type)));
}
}