diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php b/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php index adbd9191928872665daedbb13ad6b0bf6ddfdb54..b7a92830368380a886e83670f32842f05b015af3 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php @@ -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; } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/CckFile.php b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/CckFile.php new file mode 100644 index 0000000000000000000000000000000000000000..b0f48fa453a204f21acfb5a6f55f2ce638c6bf36 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/CckFile.php @@ -0,0 +1,47 @@ +<?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; + } + +} diff --git a/core/modules/migrate_drupal/src/Tests/Dump/Drupal6FieldInstance.php b/core/modules/migrate_drupal/src/Tests/Dump/Drupal6FieldInstance.php index 62a2dab61cf525d38a03860f1071003fed15bb18..870f589eaee5d7a435d13f4add582ef5539d5fed 100644 --- a/core/modules/migrate_drupal/src/Tests/Dump/Drupal6FieldInstance.php +++ b/core/modules/migrate_drupal/src/Tests/Dump/Drupal6FieldInstance.php @@ -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( diff --git a/core/modules/migrate_drupal/src/Tests/Dump/Drupal6Node.php b/core/modules/migrate_drupal/src/Tests/Dump/Drupal6Node.php index 55be0d4a2d9c44b6a2cbd64b28ed0c8eb6e9486a..f86e4652e38df1bf3d901e257e91c0f2eb391c75 100644 --- a/core/modules/migrate_drupal/src/Tests/Dump/Drupal6Node.php +++ b/core/modules/migrate_drupal/src/Tests/Dump/Drupal6Node.php @@ -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); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateCckFieldValuesTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateCckFieldValuesTest.php index c3e8fbb239bf4c6ff0089c068f3b91649f8ea3af..2ef6b7745afa0a5a8de09069a50fe5bc2a9a2ca9 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateCckFieldValuesTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateCckFieldValuesTest.php @@ -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);