Commit 41a3319b authored by alexpott's avatar alexpott
Browse files

Issue #2394567 by benjy: File field need associated metadata during cck_field migration

parent da288643
......@@ -101,6 +101,16 @@ public function loadMultiple(EntityStorageInterface $storage, array $sub_ids = N
],
];
}
elseif ($data['type'] === 'filefield') {
$migration->process[$field_name] = [
'plugin' => 'd6_cck_file',
'source' => [
$field_name,
$field_name . '_list',
$field_name . '_data',
],
];
}
else {
$migration->process[$field_name] = $field_name;
}
......
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Plugin\migrate\process\d6\CckFile.
*/
namespace Drupal\migrate_drupal\Plugin\migrate\process\d6;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\Row;
use Drupal\migrate\Plugin\migrate\process\Route;
/**
* @MigrateProcessPlugin(
* id = "d6_cck_file"
* )
*/
class CckFile extends Route implements ContainerFactoryPluginInterface {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
list($fid, $list, $data) = $value;
// If $fid is still an array at this point, that's because we have a file
// attachment as per D6 core. If not, then we have a filefield from contrib.
if (is_array($fid)) {
$list = $fid['list'];
$fid = $fid['fid'];
}
else {
$options = unserialize($data);
}
$file = [
'target_id' => $fid,
'display' => isset($list) ? $list : 0,
'description' => isset($options['description']) ? $options['description'] : '',
];
return $file;
}
}
......@@ -1070,10 +1070,10 @@ public function load() {
'field_name' => 'field_test_filefield',
'module' => 'filefield',
'type' => 'filefield',
'global_settings' => 'a:3:{s:10:"list_field";s:1:"0";s:12:"list_default";i:1;s:17:"description_field";s:1:"1";}',
'global_settings' => 'a:3:{s:10:"list_field";s:1:"0";s:12:"list_default";i:1;s:17:"description_field";s:21:"test file description";}',
'multiple' => 0,
'db_storage' => 1,
'db_columns' => 'a:0:{}',
'db_columns' => 'a:3:{s:3:"fid";a:3:{s:4:"type";s:3:"int";s:8:"not null";b:0;s:5:"views";b:1;}s:4:"list";a:4:{s:4:"type";s:3:"int";s:4:"size";s:4:"tiny";s:8:"not null";b:0;s:5:"views";b:1;}s:4:"data";a:3:{s:4:"type";s:4:"text";s:9:"serialize";b:1;s:5:"views";b:1;}}',
'active' => 1,
))
->values(array(
......
......@@ -530,6 +530,24 @@ public function load() {
'type' => 'text',
'not null' => FALSE,
),
'field_test_filefield_fid' => array(
'description' => 'The file id.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'field_test_filefield_list' => array(
'description' => 'File list field.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'field_test_filefield_data' => array(
'description' => 'The file meta.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
),
'primary key' => array('vid'),
));
......@@ -546,6 +564,9 @@ public function load() {
'field_test_link_url',
'field_test_link_title',
'field_test_link_attributes',
'field_test_filefield_fid',
'field_test_filefield_list',
'field_test_filefield_data'
))
->values(array(
'nid' => 1,
......@@ -558,6 +579,9 @@ public function load() {
'field_test_link_url' => 'http://drupal.org/project/drupal',
'field_test_link_title' => 'Drupal project page',
'field_test_link_attributes' => 's:32:"a:1:{s:6:"target";s:6:"_blank";}";";',
'field_test_filefield_fid' => 1,
'field_test_filefield_list' => 1,
'field_test_filefield_data' => 'a:1:{s:11:"description";s:4:"desc";}'
))
->values(array(
'nid' => 1,
......@@ -570,6 +594,9 @@ public function load() {
'field_test_link_url' => 'http://drupal.org/project/drupal',
'field_test_link_title' => 'Drupal project page',
'field_test_link_attributes' => 's:32:"a:1:{s:6:"target";s:6:"_blank";}";',
'field_test_filefield_fid' => 1,
'field_test_filefield_list' => 1,
'field_test_filefield_data' => 'a:1:{s:11:"description";s:4:"desc";}'
))
->values(array(
'nid' => 2,
......@@ -582,6 +609,9 @@ public function load() {
'field_test_link_url' => 'http://groups.drupal.org/',
'field_test_link_title' => 'Drupal Groups',
'field_test_link_attributes' => 's:6:"a:0:{}";',
'field_test_filefield_fid' => 2,
'field_test_filefield_list' => 1,
'field_test_filefield_data' => 'a:1:{s:11:"description";s:4:"desc";}'
))
->values(array(
'nid' => 2,
......@@ -594,6 +624,9 @@ public function load() {
'field_test_link_url' => 'http://groups.drupal.org/',
'field_test_link_title' => 'Drupal Groups',
'field_test_link_attributes' => 's:6:"a:0:{}";',
'field_test_filefield_fid' => 2,
'field_test_filefield_list' => 1,
'field_test_filefield_data' => 'a:1:{s:11:"description";s:4:"desc";}'
))
->execute();
$this->setModuleVersion('content', 6001);
......
......@@ -22,7 +22,7 @@ class MigrateCckFieldValuesTest extends MigrateNodeTestBase {
*
* @var array
*/
public static $modules = array('node', 'text', 'link');
public static $modules = array('node', 'text', 'link', 'file');
/**
* {@inheritdoc}
......@@ -126,6 +126,17 @@ protected function setUp() {
'bundle' => 'story',
))->save();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_filefield',
'type' => 'file',
))->save();
entity_create('field_config', array(
'entity_type' => 'node',
'field_name' => 'field_test_filefield',
'bundle' => 'story',
))->save();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_field_formatter_settings' => array(
......@@ -171,6 +182,10 @@ public function testCckFields() {
$this->assertIdentical($node->field_test_link->route_parameters, []);
$this->assertIdentical($node->field_test_link->options['attributes'], ['target' => '_blank']);
// Test the file field meta.
$this->assertIdentical($node->field_test_filefield->description, 'desc');
$this->assertIdentical($node->field_test_filefield->target_id, '1');
$planet_node = Node::load(3);
$this->assertEqual($planet_node->field_multivalue->value, 33);
$this->assertEqual($planet_node->field_multivalue[1]->value, 44);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment