diff --git a/core/modules/file/src/Plugin/migrate/cckfield/FileField.php b/core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php similarity index 91% rename from core/modules/file/src/Plugin/migrate/cckfield/FileField.php rename to core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php index 022f01e..4e4e456 100644 --- a/core/modules/file/src/Plugin/migrate/cckfield/FileField.php +++ b/core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php @@ -2,10 +2,10 @@ /** * @file - * Contains \Drupal\file\Plugin\migrate\cckfield\FileField. + * Contains \Drupal\file\Plugin\migrate\cckfield\d6\FileField. */ -namespace Drupal\file\Plugin\migrate\cckfield; +namespace Drupal\file\Plugin\migrate\cckfield\d6; use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\Row; diff --git a/core/modules/file/src/Plugin/migrate/cckfield/d7/FileField.php b/core/modules/file/src/Plugin/migrate/cckfield/d7/FileField.php new file mode 100644 index 0000000..d9426fd --- /dev/null +++ b/core/modules/file/src/Plugin/migrate/cckfield/d7/FileField.php @@ -0,0 +1,67 @@ + 'file_generic', + ]; + } + + /** + * {@inheritdoc} + */ + public function getFieldFormatterMap() { + return [ + 'default' => 'file_default', + 'url_plain' => 'file_url_plain', + 'path_plain' => 'file_url_plain', + 'image_plain' => 'image', + 'image_nodelink' => 'image', + 'image_imagelink' => 'image', + ]; + } + + /** + * {@inheritdoc} + */ + public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) { + $process = [ + 'plugin' => 'iterator', + 'source' => $field_name, + 'process' => [ + 'target_id' => 'fid', + 'display' => 'display', + 'description' => 'description', + ], + ]; + $migration->mergeProcessOfProperty($field_name, $process); + } + + /** + * {@inheritdoc} + */ + public function getFieldType(Row $row) { + return $row->getSourceProperty('widget_type') == 'imagefield_widget' ? 'image' : 'file'; + } + +} diff --git a/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php b/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php new file mode 100644 index 0000000..e818d70 --- /dev/null +++ b/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php @@ -0,0 +1,45 @@ + 'iterator', + 'source' => $field_name, + 'process' => [ + 'target_id' => 'fid', + 'alt' => 'alt', + 'title' => 'title', + 'width' => 'width', + 'height' => 'height', + ], + ]; + $migration->mergeProcessOfProperty($field_name, $process); + } + +} diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php index ef7e2bf..db1576a 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -4330,6 +4330,33 @@ 'mysql_character_set' => 'utf8', )); +$connection->insert('field_data_field_file') +->fields(array( + 'entity_type', + 'bundle', + 'deleted', + 'entity_id', + 'revision_id', + 'language', + 'delta', + 'field_file_fid', + 'field_file_display', + 'field_file_description', +)) +->values(array( + 'entity_type' => 'node', + 'bundle' => 'test_content_type', + 'deleted' => '0', + 'entity_id' => '1', + 'revision_id' => '1', + 'language' => 'und', + 'delta' => '0', + 'field_file_fid' => '2', + 'field_file_display' => '1', + 'field_file_description' => 'file desc', +)) +->execute(); + $connection->schema()->createTable('field_data_field_float', array( 'fields' => array( 'entity_type' => array( @@ -6065,6 +6092,33 @@ 'mysql_character_set' => 'utf8', )); +$connection->insert('field_revision_field_file') +->fields(array( + 'entity_type', + 'bundle', + 'deleted', + 'entity_id', + 'revision_id', + 'language', + 'delta', + 'field_file_fid', + 'field_file_display', + 'field_file_description', +)) +->values(array( + 'entity_type' => 'node', + 'bundle' => 'test_content_type', + 'deleted' => '0', + 'entity_id' => '1', + 'revision_id' => '1', + 'language' => 'und', + 'delta' => '0', + 'field_file_fid' => '2', + 'field_file_display' => '1', + 'field_file_description' => 'file desc', +)) +->execute(); + $connection->schema()->createTable('field_revision_field_float', array( 'fields' => array( 'entity_type' => array( @@ -7337,6 +7391,13 @@ 'module' => 'file', 'type' => 'node', 'id' => '1', + 'count' => '2', +)) +->values(array( + 'fid' => '2', + 'module' => 'file', + 'type' => 'node', + 'id' => '1', 'count' => '1', )) ->execute(); diff --git a/core/modules/node/src/Tests/Migrate/d7/MigrateNodeTest.php b/core/modules/node/src/Tests/Migrate/d7/MigrateNodeTest.php index 9a9024b..90a39bd 100644 --- a/core/modules/node/src/Tests/Migrate/d7/MigrateNodeTest.php +++ b/core/modules/node/src/Tests/Migrate/d7/MigrateNodeTest.php @@ -39,6 +39,7 @@ protected function setUp() { $this->installEntitySchema('node'); $this->installEntitySchema('comment'); $this->installEntitySchema('taxonomy_term'); + $this->installEntitySchema('file'); $this->installConfig(static::$modules); $this->installSchema('node', ['node_access']); $this->installSchema('system', ['sequences']); @@ -112,7 +113,7 @@ protected function assertEntity($id, $type, $langcode, $title, $uid, $status, $c protected function assertRevision($id, $title, $uid, $log, $timestamp) { $revision = \Drupal::entityManager()->getStorage('node')->loadRevision($id); $this->assertTrue($revision instanceof NodeInterface); - $this->assertIdentical($title, $revision->getTitle()); + $this->assertIdentical($title, $revision->getTitle()); $this->assertIdentical($uid, $revision->getRevisionAuthor()->id()); $this->assertIdentical($log, $revision->revision_log->value); $this->assertIdentical($timestamp, $revision->getRevisionCreationTime()); @@ -134,6 +135,14 @@ public function testNode() { $this->assertIdentical('Some more text', $node->field_text_list[0]->value); $this->assertIdentical('7', $node->field_integer_list[0]->value); $this->assertIdentical('qwerty', $node->field_text->value); + $this->assertIdentical('2', $node->field_file->target_id); + $this->assertIdentical('file desc', $node->field_file->description); + $this->assertTrue($node->field_file->display); + $this->assertIdentical('1', $node->field_images->target_id); + $this->assertIdentical('alt text', $node->field_images->alt); + $this->assertIdentical('title text', $node->field_images->title); + $this->assertIdentical('93', $node->field_images->width); + $this->assertIdentical('93', $node->field_images->height); } }