Commit 53b7b924 authored by alexpott's avatar alexpott
Browse files

Issue #2604484 by quietone, dobe, drclaw, skyredwang, mikeryan, grahl: Migrate...

Issue #2604484 by quietone, dobe, drclaw, skyredwang, mikeryan, grahl: Migrate Drupal 7 image and file fields
parent b8af90db
......@@ -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;
......
<?php
/**
* @file
* Contains \Drupal\file\Plugin\migrate\cckfield\d7\FileField.
*/
namespace Drupal\file\Plugin\migrate\cckfield\d7;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
/**
* @MigrateCckField(
* id = "file",
* )
*/
class FileField extends CckFieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldWidgetMap() {
return [
'filefield_widget' => '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';
}
}
<?php
/**
* @file
* Contains \Drupal\file\Plugin\migrate\cckfield\d7\ImageField.
*/
namespace Drupal\file\Plugin\migrate\cckfield\d7;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
/**
* @MigrateCckField(
* id = "image"
* )
*/
class ImageField extends CckFieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return array();
}
/**
* {@inheritdoc}
*/
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = [
'plugin' => 'iterator',
'source' => $field_name,
'process' => [
'target_id' => 'fid',
'alt' => 'alt',
'title' => 'title',
'width' => 'width',
'height' => 'height',
],
];
$migration->mergeProcessOfProperty($field_name, $process);
}
}
......@@ -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();
......@@ -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']);
......@@ -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);
}
}
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