diff --git a/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php b/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php index 7cb2048a9ecf4a5c1d74bfab88ad30c731d0059f..dc3b9cd5aa1c6b409dceeff53e179ed70a1e6cc1 100644 --- a/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php +++ b/core/modules/file/src/Plugin/migrate/cckfield/d7/ImageField.php @@ -2,42 +2,16 @@ namespace Drupal\file\Plugin\migrate\cckfield\d7; -@trigger_error('ImageField is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\file\Plugin\migrate\field\d7\ImageField instead.', E_USER_DEPRECATED); +@trigger_error('ImageField is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\image\Plugin\migrate\field\d7\ImageField instead. See https://www.drupal.org/node/2936061.', E_USER_DEPRECATED); -use Drupal\migrate\Plugin\MigrationInterface; -use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase; +use Drupal\image\Plugin\migrate\cckfield\d7\ImageField as LegacyImageField; /** - * @MigrateCckField( - * id = "image", - * core = {7}, - * source_module = "image", - * destination_module = "file" - * ) + * CCK plugin for image fields. * * @deprecated in Drupal 8.3.x, to be removed before Drupal 9.0.x. Use - * \Drupal\file\Plugin\migrate\field\d7\ImageField instead. + * \Drupal\image\Plugin\migrate\field\d7\ImageField instead. * - * @see https://www.drupal.org/node/2751897 + * @see https://www.drupal.org/node/2936061 */ -class ImageField extends CckFieldPluginBase { - - /** - * {@inheritdoc} - */ - public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) { - $process = [ - 'plugin' => 'sub_process', - 'source' => $field_name, - 'process' => [ - 'target_id' => 'fid', - 'alt' => 'alt', - 'title' => 'title', - 'width' => 'width', - 'height' => 'height', - ], - ]; - $migration->mergeProcessOfProperty($field_name, $process); - } - -} +class ImageField extends LegacyImageField {} diff --git a/core/modules/file/src/Plugin/migrate/field/d6/ImageField.php b/core/modules/file/src/Plugin/migrate/field/d6/ImageField.php index 3ec65ddece3f14b236d45443281bb0ef62ee1bcd..c05d8c3665155710943864a9f2cb86ba236e5af1 100644 --- a/core/modules/file/src/Plugin/migrate/field/d6/ImageField.php +++ b/core/modules/file/src/Plugin/migrate/field/d6/ImageField.php @@ -2,12 +2,16 @@ namespace Drupal\file\Plugin\migrate\field\d6; +@trigger_error('ImageField is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use \Drupal\image\Plugin\migrate\field\d6\ImageField instead. See https://www.drupal.org/node/2936061.', E_USER_DEPRECATED); + +use Drupal\image\Plugin\migrate\field\d6\ImageField as NonLegacyImageField; + /** - * @MigrateField( - * id = "imagefield", - * core = {6}, - * source_module = "imagefield", - * destination_module = "file" - * ) + * Field plugin for image fields. + * + * @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.x. Use + * \Drupal\image\Plugin\migrate\field\d6\ImageField instead. + * + * @see https://www.drupal.org/node/2936061 */ -class ImageField extends FileField {} +class ImageField extends NonLegacyImageField {} diff --git a/core/modules/file/src/Plugin/migrate/field/d7/ImageField.php b/core/modules/file/src/Plugin/migrate/field/d7/ImageField.php index ea2005e1c23d79bc9ea822da688b7d21d76daef6..29da4d2b673092f89cf96ae26ba29e02839a76ef 100644 --- a/core/modules/file/src/Plugin/migrate/field/d7/ImageField.php +++ b/core/modules/file/src/Plugin/migrate/field/d7/ImageField.php @@ -2,35 +2,16 @@ namespace Drupal\file\Plugin\migrate\field\d7; -use Drupal\migrate\Plugin\MigrationInterface; -use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase; +@trigger_error('ImageField is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use \Drupal\image\Plugin\migrate\field\d7\ImageField instead. See https://www.drupal.org/node/2936061.', E_USER_DEPRECATED); + +use Drupal\image\Plugin\migrate\field\d7\ImageField as NonLegacyImageField; /** - * @MigrateField( - * id = "image", - * core = {7}, - * source_module = "image", - * destination_module = "file" - * ) + * Field plugin for image fields. + * + * @deprecated in Drupal 8.5.x, to be removed before Drupal 9.0.x. Use + * \Drupal\image\Plugin\migrate\field\d7\ImageField instead. + * + * @see https://www.drupal.org/node/2936061 */ -class ImageField extends FieldPluginBase { - - /** - * {@inheritdoc} - */ - public function processFieldValues(MigrationInterface $migration, $field_name, $data) { - $process = [ - 'plugin' => 'sub_process', - 'source' => $field_name, - 'process' => [ - 'target_id' => 'fid', - 'alt' => 'alt', - 'title' => 'title', - 'width' => 'width', - 'height' => 'height', - ], - ]; - $migration->mergeProcessOfProperty($field_name, $process); - } - -} +class ImageField extends NonLegacyImageField {} diff --git a/core/modules/file/tests/src/Unit/Plugin/migrate/field/d6/ImageFieldTest.php b/core/modules/file/tests/src/Unit/Plugin/migrate/field/d6/ImageFieldTest.php new file mode 100644 index 0000000000000000000000000000000000000000..c84bc6e23bb1073bcc3358c58a31a6b32a1782a2 --- /dev/null +++ b/core/modules/file/tests/src/Unit/Plugin/migrate/field/d6/ImageFieldTest.php @@ -0,0 +1,60 @@ +plugin = new ImageField([], 'image', []); + + $migration = $this->prophesize(MigrationInterface::class); + + // The plugin's processFieldValues() method will call + // mergeProcessOfProperty() 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 mergeProcessOfProperty(). + $migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array')) + ->will(function ($arguments) use ($migration) { + $migration->getProcess()->willReturn($arguments[1]); + }); + $this->migration = $migration->reveal(); + } + + /** + * @covers ::processFieldValues + * @expectedDeprecation ImageField is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use \Drupal\image\Plugin\migrate\field\d6\ImageField instead. See https://www.drupal.org/node/2936061. + */ + public function testProcessFieldValues() { + $this->plugin->processFieldValues($this->migration, 'somefieldname', []); + + $expected = [ + 'plugin' => 'd6_field_file', + 'source' => 'somefieldname', + ]; + $this->assertSame($expected, $this->migration->getProcess()); + } + +} diff --git a/core/modules/file/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php b/core/modules/file/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php index 3cab3537089f8b58e24db98a073c0b439226c4bd..9e9c3fa21c4b8aae2a222b937c790de028631ba9 100644 --- a/core/modules/file/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php +++ b/core/modules/file/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php @@ -10,6 +10,7 @@ /** * @coversDefaultClass \Drupal\file\Plugin\migrate\field\d7\ImageField * @group file + * @group legacy */ class ImageFieldTest extends UnitTestCase { @@ -44,6 +45,7 @@ protected function setUp() { /** * @covers ::processFieldValues + * @expectedDeprecation ImageField is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use \Drupal\image\Plugin\migrate\field\d7\ImageField instead. See https://www.drupal.org/node/2936061. */ public function testProcessFieldValues() { $this->plugin->processFieldValues($this->migration, 'somefieldname', []); diff --git a/core/modules/image/src/Plugin/migrate/cckfield/d7/ImageField.php b/core/modules/image/src/Plugin/migrate/cckfield/d7/ImageField.php new file mode 100644 index 0000000000000000000000000000000000000000..081ff055be42ef9497a36da0f2d56de80fafc6d4 --- /dev/null +++ b/core/modules/image/src/Plugin/migrate/cckfield/d7/ImageField.php @@ -0,0 +1,43 @@ + 'sub_process', + '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/image/src/Plugin/migrate/field/d6/ImageField.php b/core/modules/image/src/Plugin/migrate/field/d6/ImageField.php new file mode 100644 index 0000000000000000000000000000000000000000..072c4c2116573c2fd7afae79e1a1230be214d66c --- /dev/null +++ b/core/modules/image/src/Plugin/migrate/field/d6/ImageField.php @@ -0,0 +1,15 @@ + 'sub_process', + '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/image/tests/src/Kernel/Migrate/d6/MigrateImageTest.php b/core/modules/image/tests/src/Kernel/Migrate/d6/MigrateImageTest.php new file mode 100644 index 0000000000000000000000000000000000000000..7fc0b0bafb3423aaae9818a588ad7b388d398acc --- /dev/null +++ b/core/modules/image/tests/src/Kernel/Migrate/d6/MigrateImageTest.php @@ -0,0 +1,51 @@ +setUpMigratedFiles(); + $this->installSchema('file', ['file_usage']); + $this->executeMigrations([ + 'd6_node', + ]); + } + + /** + * Test image migration from Drupal 6 to 8. + */ + public function testNode() { + $node = Node::load(9); + // Test the image field sub fields. + $this->assertSame('2', $node->field_test_imagefield->target_id); + $this->assertSame('Test alt', $node->field_test_imagefield->alt); + $this->assertSame('Test title', $node->field_test_imagefield->title); + $this->assertSame('80', $node->field_test_imagefield->width); + $this->assertSame('60', $node->field_test_imagefield->height); + } + +} diff --git a/core/modules/image/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php b/core/modules/image/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php new file mode 100644 index 0000000000000000000000000000000000000000..198aa9ddfb7b66d69ee6d7b74dbbc26ea17bb03b --- /dev/null +++ b/core/modules/image/tests/src/Unit/Plugin/migrate/field/d7/ImageFieldTest.php @@ -0,0 +1,65 @@ +plugin = new ImageField([], 'image', []); + + $migration = $this->prophesize(MigrationInterface::class); + + // The plugin's processFieldValues() method will call + // mergeProcessOfProperty() 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 mergeProcessOfProperty(). + $migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array')) + ->will(function ($arguments) use ($migration) { + $migration->getProcess()->willReturn($arguments[1]); + }); + $this->migration = $migration->reveal(); + } + + /** + * @covers ::processFieldValues + */ + public function testProcessFieldValues() { + $this->plugin->processFieldValues($this->migration, 'somefieldname', []); + + $expected = [ + 'plugin' => 'sub_process', + 'source' => 'somefieldname', + 'process' => [ + 'target_id' => 'fid', + 'alt' => 'alt', + 'title' => 'title', + 'width' => 'width', + 'height' => 'height', + ], + ]; + $this->assertSame($expected, $this->migration->getProcess()); + } + +} diff --git a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationProvidersExistTest.php b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationProvidersExistTest.php index 9f4873a9fe6e5356479030314a1164507edb4f69..efb831269329806616c84c5816368c3e7896a585 100644 --- a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationProvidersExistTest.php +++ b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationProvidersExistTest.php @@ -87,7 +87,7 @@ public function testFieldProvidersExist() { ], 'imagefield' => [ 'source_module' => 'imagefield', - 'destination_module' => 'file', + 'destination_module' => 'image', ], 'file' => [ 'source_module' => 'file', @@ -95,7 +95,7 @@ public function testFieldProvidersExist() { ], 'image' => [ 'source_module' => 'image', - 'destination_module' => 'file', + 'destination_module' => 'image', ], 'phone' => [ 'source_module' => 'phone', diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php index 1c8a8759bcb9d7cb985ba579e162e4828c6090b1..059ba786991fdc4befac1893239129f56a9851c3 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php @@ -3780,9 +3780,9 @@ 'field_test_phone_value' => NULL, 'field_test_exclude_unset_value' => 'text for default value', 'field_test_exclude_unset_format' => '1', - 'field_test_imagefield_fid' => NULL, - 'field_test_imagefield_list' => NULL, - 'field_test_imagefield_data' => NULL, + 'field_test_imagefield_fid' => '2', + 'field_test_imagefield_list' => '1', + 'field_test_imagefield_data' => 'a:2:{s:3:"alt";s:8:"Test alt";s:5:"title";s:10:"Test title";}', 'field_test_text_single_checkbox2_value' => 'Off', 'field_test_datestamp_value2' => '1391357160', 'field_test_datetime_value2' => '2015-03-04 06:07:00', diff --git a/core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php b/core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php index 7e36364e8261fbb2def23d2a6669ca1089e941bf..284a267a1f96dda80ab8899ee452e95ebdd9c3db 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php @@ -14,7 +14,7 @@ class MigrateFieldPluginManagerTest extends MigrateDrupalTestBase { /** * {@inheritdoc} */ - public static $modules = ['system', 'user', 'field', 'migrate_drupal', 'options', 'file', 'text', 'link', 'migrate_field_plugin_manager_test']; + public static $modules = ['system', 'user', 'field', 'migrate_drupal', 'options', 'file', 'image', 'text', 'link', 'migrate_field_plugin_manager_test']; /** * Tests that the correct MigrateField plugins are used.