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

Issue #2588827 by phenaproxima, neclimdul, svendecabooter, benjy, mikeryan:...

Issue #2588827 by phenaproxima, neclimdul, svendecabooter, benjy, mikeryan: CCK migrations seem to have trouble with some checkbox types
parent 78aba37b
Branches
Tags
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
......@@ -82,6 +82,9 @@ public function prepareRow(Row $row) {
$row->setSourceProperty('widget_settings', $data['widget']);
$row->setSourceProperty('display_settings', $data['display']);
// This is for parity with the d6_field_instance plugin.
$row->setSourceProperty('widget_type', $data['widget']['type']);
return parent::prepareRow($row);
}
......
......@@ -2598,6 +2598,18 @@
'active' => '1',
'locked' => '0',
))
->values(array(
'field_name' => 'field_test_text_single_checkbox2',
'type' => 'text',
'global_settings' => "a:4:{s:15:\"text_processing\";s:1:\"0\";s:10:\"max_length\";s:0:\"\";s:14:\"allowed_values\";s:10:\"Off\r\nHello\";s:18:\"allowed_values_php\";s:0:\"\";}",
'required' => '0',
'multiple' => '0',
'db_storage' => '1',
'module' => 'text',
'db_columns' => 'a:1:{s:5:"value";a:5:{s:4:"type";s:4:"text";s:4:"size";s:3:"big";s:8:"not null";b:0;s:8:"sortable";b:1;s:5:"views";b:1;}}',
'active' => '1',
'locked' => '0',
))
->values(array(
'field_name' => 'field_test_three',
'type' => 'number_decimal',
......@@ -2944,6 +2956,18 @@
'widget_module' => 'text',
'widget_active' => '1',
))
->values(array(
'field_name' => 'field_test_text_single_checkbox2',
'type_name' => 'story',
'weight' => '19',
'label' => 'Text Single Checkbox Field 2',
'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' => 'a:5:{s:5:"label";a:2:{s:6:"format";s:5:"above";s:7:"exclude";i:0;}i:5;a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}s:6:"teaser";a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}s:4:"full";a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}i:4;a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}}',
'description' => 'Checkbox that uses keys only and no label.',
'widget_module' => 'optionwidgets',
'widget_active' => '1',
))
->values(array(
'field_name' => 'field_test_three',
'type_name' => 'story',
......@@ -3159,6 +3183,11 @@
'not null' => FALSE,
'size' => 'normal',
),
'field_test_text_single_checkbox2_value' => array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
),
),
'primary key' => array(
'vid',
......@@ -3199,6 +3228,7 @@
'field_test_imagefield_fid',
'field_test_imagefield_list',
'field_test_imagefield_data',
'field_test_text_single_checkbox2_value',
))
->values(array(
'nid' => '1',
......@@ -3227,6 +3257,7 @@
'field_test_imagefield_fid' => NULL,
'field_test_imagefield_list' => NULL,
'field_test_imagefield_data' => NULL,
'field_test_text_single_checkbox2_value' => 'Hello',
))
->values(array(
'nid' => '1',
......@@ -3255,6 +3286,7 @@
'field_test_imagefield_fid' => NULL,
'field_test_imagefield_list' => NULL,
'field_test_imagefield_data' => NULL,
'field_test_text_single_checkbox2_value' => NULL,
))
->values(array(
'nid' => '2',
......@@ -3283,6 +3315,7 @@
'field_test_imagefield_fid' => NULL,
'field_test_imagefield_list' => NULL,
'field_test_imagefield_data' => NULL,
'field_test_text_single_checkbox2_value' => NULL,
))
->values(array(
'nid' => '2',
......@@ -3311,6 +3344,7 @@
'field_test_imagefield_fid' => NULL,
'field_test_imagefield_list' => NULL,
'field_test_imagefield_data' => NULL,
'field_test_text_single_checkbox2_value' => NULL,
))
->values(array(
'nid' => '9',
......@@ -3339,6 +3373,7 @@
'field_test_imagefield_fid' => NULL,
'field_test_imagefield_list' => NULL,
'field_test_imagefield_data' => NULL,
'field_test_text_single_checkbox2_value' => NULL,
))
->execute();
 
......@@ -24629,6 +24664,50 @@
'weight' => '0',
'file' => 'sites/all/modules/cck/includes/content.admin.inc',
))
->values(array(
'path' => 'admin/content/node-type/story/fields/field_test_text_single_checkbox2',
'load_functions' => '',
'to_arg_functions' => '',
'access_callback' => 'user_access',
'access_arguments' => 'a:1:{i:0;s:24:"administer content types";}',
'page_callback' => 'drupal_get_form',
'page_arguments' => 'a:3:{i:0;s:23:"content_field_edit_form";i:1;s:5:"story";i:2;s:32:"field_test_text_single_checkbox2";}',
'fit' => '63',
'number_parts' => '6',
'tab_parent' => 'admin/content/node-type/story/fields',
'tab_root' => 'admin/content/node-type/story',
'title' => 'Text Single Checkbox Field 2',
'title_callback' => 't',
'title_arguments' => '',
'type' => '128',
'block_callback' => '',
'description' => '',
'position' => '',
'weight' => '0',
'file' => 'sites/all/modules/cck/includes/content.admin.inc',
))
->values(array(
'path' => 'admin/content/node-type/story/fields/field_test_text_single_checkbox2/remove',
'load_functions' => '',
'to_arg_functions' => '',
'access_callback' => 'user_access',
'access_arguments' => 'a:1:{i:0;s:24:"administer content types";}',
'page_callback' => 'drupal_get_form',
'page_arguments' => 'a:3:{i:0;s:25:"content_field_remove_form";i:1;s:5:"story";i:2;s:32:"field_test_text_single_checkbox2";}',
'fit' => '127',
'number_parts' => '7',
'tab_parent' => '',
'tab_root' => 'admin/content/node-type/story/fields/field_test_text_single_checkbox2/remove',
'title' => 'Remove field',
'title_callback' => 't',
'title_arguments' => '',
'type' => '4',
'block_callback' => '',
'description' => '',
'position' => '',
'weight' => '0',
'file' => 'sites/all/modules/cck/includes/content.admin.inc',
))
->values(array(
'path' => 'admin/content/node-type/story/fields/field_test_three',
'load_functions' => '',
......
......@@ -38,35 +38,55 @@ public function getFieldFormatterMap() {
/**
* {@inheritdoc}
*/
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = array(
array(
'plugin' => 'iterator',
'source' => $field_name,
// See \Drupal\migrate_drupal\Plugin\migrate\source\d6\User::baseFields(),
// signature_format for an example of the YAML that represents this
// process array.
'process' => [
'value' => 'value',
'format' => [
[
'plugin' => 'static_map',
'bypass' => TRUE,
'source' => 'format',
'map' => [0 => NULL],
],
[
'plugin' => 'skip_on_empty',
'method' => 'process',
],
[
'plugin' => 'migration',
'migration' => 'd6_filter_format',
'source' => 'format',
public function processCckFieldValues(MigrationInterface $migration, $field_name, $field_info) {
if ($field_info['widget_type'] == 'optionwidgets_onoff') {
$process = [
'value' => [
'plugin' => 'static_map',
'source' => 'value',
'default_value' => 0,
],
];
$checked_value = explode("\n", $field_info['global_settings']['allowed_values'])[1];
if (strpos($checked_value, '|') !== FALSE) {
$checked_value = substr($checked_value, 0, strpos($checked_value, '|'));
}
$process['value']['map'][$checked_value] = 1;
}
else {
// See \Drupal\migrate_drupal\Plugin\migrate\source\d6\User::baseFields(),
// signature_format for an example of the YAML that represents this
// process array.
$process = [
'value' => 'value',
'format' => [
[
'plugin' => 'static_map',
'bypass' => TRUE,
'source' => 'format',
'map' => [0 => NULL],
],
[
'plugin' => 'skip_on_empty',
'method' => 'process',
],
[
'plugin' => 'migration',
'migration' => [
'd6_filter_format',
'd7_filter_format',
],
'source' => 'format',
],
],
),
];
}
$process = array(
'plugin' => 'iterator',
'source' => $field_name,
'process' => $process,
);
$migration->setProcessOfProperty($field_name, $process);
}
......
<?php
/**
* @file
* Contains \Drupal\Tests\text\Unit\Migrate\TextFieldTest.
*/
namespace Drupal\Tests\text\Unit\Migrate;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\text\Plugin\migrate\cckfield\TextField;
use Prophecy\Argument;
/**
* @coversDefaultClass \Drupal\text\Plugin\migrate\cckfield\TextField
* @group text
*/
class TextFieldTest extends UnitTestCase {
/**
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
*/
protected $plugin;
/**
* @var \Drupal\migrate\Entity\MigrationInterface
*/
protected $migration;
/**
* {@inheritdoc}
*/
public function setUp() {
$this->plugin = new TextField([], 'text', []);
$migration = $this->prophesize(MigrationInterface::class);
// The plugin's processCckFieldValues() method will call
// setProcessOfProperty() and return nothing. So, in order to examine the
// process pipeline created by the plugin, we need to ensure that
// getProcess() always returns the last input to setProcessOfProperty().
$migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
->will(function($arguments) use ($migration) {
$migration->getProcess()->willReturn($arguments[1]);
});
$this->migration = $migration->reveal();
}
/**
* @covers ::processCckFieldValues
*/
public function testProcessFilteredTextFieldValues() {
$field_info = [
'widget_type' => 'text_textfield',
];
$this->plugin->processCckFieldValues($this->migration, 'body', $field_info);
$process = $this->migration->getProcess();
$this->assertSame('iterator', $process['plugin']);
$this->assertSame('body', $process['source']);
$this->assertSame('value', $process['process']['value']);
// Ensure that filter format IDs will be looked up in the filter format
// migrations.
$lookup = $process['process']['format'][2];
$this->assertSame('migration', $lookup['plugin']);
$this->assertContains('d6_filter_format', $lookup['migration']);
$this->assertContains('d7_filter_format', $lookup['migration']);
$this->assertSame('format', $lookup['source']);
}
/**
* @covers ::processCckFieldValues
*/
public function testProcessBooleanTextImplicitValues() {
$info = array(
'widget_type' => 'optionwidgets_onoff',
'global_settings' => array(
'allowed_values' => "foo\nbar",
)
);
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
$expected = [
'value' => [
'plugin' => 'static_map',
'source' => 'value',
'default_value' => 0,
'map' => [
'bar' => 1,
],
],
];
$this->assertSame($expected, $this->migration->getProcess()['process']);
}
/**
* @covers ::processCckFieldValues
*/
public function testProcessBooleanTextExplicitValues() {
$info = array(
'widget_type' => 'optionwidgets_onoff',
'global_settings' => array(
'allowed_values' => "foo|Foo\nbaz|Baz",
)
);
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
$expected = [
'value' => [
'plugin' => 'static_map',
'source' => 'value',
'default_value' => 0,
'map' => [
'baz' => 1,
],
],
];
$this->assertSame($expected, $this->migration->getProcess()['process']);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment