Commit efc4dd97 authored by alexpott's avatar alexpott

Issue #3004929 by mikelutz, heddn: Fix 'The...

Issue #3004929 by mikelutz, heddn: Fix 'The Drupal\migrate\Plugin\migrate\process\Migration is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use Drupal\migrate\Plugin\migrate\process\MigrationLookup'
parent bae8faf4
......@@ -4,6 +4,7 @@
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\MigrateProcessInterface;
......@@ -19,13 +20,27 @@
class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The migration process plugin, configured for lookups in d6_custom_block
* and d7_custom_block.
* The migration process plugin.
*
* The plugin is configured for lookups in d6_custom_block and
* d7_custom_block.
*
* @var \Drupal\migrate\Plugin\MigrateProcessInterface
*
* @deprecated in drupal:8.8.x and is removed from drupal:9.0.0. Use
* the migrate.lookup service instead.
*
* @see https://www.drupal.org/node/3047268
*/
protected $migrationPlugin;
/**
* The migrate lookup service.
*
* @var \Drupal\migrate\MigrateLookupInterface
*/
protected $migrateLookup;
/**
* The block_content entity storage handler.
*
......@@ -34,12 +49,32 @@ class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginI
protected $blockContentStorage;
/**
* {@inheritdoc}
* Constructs a BlockPluginId object.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The block content storage object.
* @param \Drupal\migrate\MigrateLookupInterface $migrate_lookup
* The migrate lookup service.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageInterface $storage, MigrateProcessInterface $migration_plugin) {
// @codingStandardsIgnoreLine
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageInterface $storage, $migrate_lookup) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
if ($migrate_lookup instanceof MigrateProcessInterface) {
@trigger_error('Passing a migration process plugin as the fifth argument to ' . __METHOD__ . ' is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268', E_USER_DEPRECATED);
$this->migrationPlugin = $migrate_lookup;
$migrate_lookup = \Drupal::service('migrate.lookup');
}
elseif (!$migrate_lookup instanceof MigrateLookupInterface) {
throw new \InvalidArgumentException("The fifth argument to " . __METHOD__ . " must be an instance of MigrateLookupInterface.");
}
$this->blockContentStorage = $storage;
$this->migrationPlugin = $migration_plugin;
$this->migrateLookup = $migrate_lookup;
}
/**
......@@ -47,18 +82,12 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
$entity_type_manager = $container->get('entity_type.manager');
$migration_configuration = [
'migration' => [
'd6_custom_block',
'd7_custom_block',
],
];
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$entity_type_manager->getDefinition('block_content') ? $entity_type_manager->getStorage('block_content') : NULL,
$container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_configuration, $migration)
$container->get('migrate.lookup')
);
}
......@@ -77,17 +106,35 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
return 'aggregator_feed_block';
}
break;
case 'menu':
return "system_menu_block:$delta";
case 'block':
if ($this->blockContentStorage) {
$block_id = $this->migrationPlugin
->transform($delta, $migrate_executable, $row, $destination_property);
if ($block_id) {
// This BC layer is included because if the plugin constructor was
// called in the legacy way with a migration_lookup process plugin,
// it may have been preconfigured with a different migration to
// look up against. While this is unlikely, for maximum BC we will
// continue to use the plugin to do the lookup if it is provided,
// and support for this will be removed in Drupal 9.
if ($this->migrationPlugin) {
$block_id = $this->migrationPlugin
->transform($delta, $migrate_executable, $row, $destination_property);
}
else {
$lookup_result = $this->migrateLookup->lookup(['d6_custom_block', 'd7_custom_block'], [$delta]);
if ($lookup_result) {
$block_id = $lookup_result[0]['id'];
}
}
if (!empty($block_id)) {
return 'block_content:' . $this->blockContentStorage->load($block_id)->uuid();
}
}
break;
default:
break;
}
......
......@@ -4,6 +4,7 @@
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
......@@ -27,13 +28,27 @@ class BlockVisibility extends ProcessPluginBase implements ContainerFactoryPlugi
protected $moduleHandler;
/**
* The migration process plugin, configured for lookups in the d6_user_role
* and d7_user_role migrations.
* The migration process plugin.
*
* The plugin is configured for lookups in the d6_user_role and d7_user_role
* migrations.
*
* @var \Drupal\migrate\Plugin\MigrateProcessInterface
*
* @deprecated in drupal:8.8.x and is removed from drupal:9.0.0. Use
* the migrate.lookup service instead.
*
* @see https://www.drupal.org/node/3047268
*/
protected $migrationPlugin;
/**
* The migrate lookup service.
*
* @var \Drupal\migrate\MigrateLookupInterface
*/
protected $migrateLookup;
/**
* Whether or not to skip blocks that use PHP for visibility. Only applies
* if the PHP module is not enabled.
......@@ -43,12 +58,32 @@ class BlockVisibility extends ProcessPluginBase implements ContainerFactoryPlugi
protected $skipPHP = FALSE;
/**
* {@inheritdoc}
* Constructs a BlockVisibility object.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
* @param \Drupal\migrate\MigrateLookupInterface $migrate_lookup
* The migrate lookup service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler, MigrateProcessInterface $migration_plugin) {
// @codingStandardsIgnoreLine
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler, $migrate_lookup) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
if ($migrate_lookup instanceof MigrateProcessInterface) {
@trigger_error('Passing a migration process plugin as the fifth argument to ' . __METHOD__ . ' is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268', E_USER_DEPRECATED);
$this->migrationPlugin = $migrate_lookup;
$migrate_lookup = \Drupal::service('migrate.lookup');
}
elseif (!$migrate_lookup instanceof MigrateLookupInterface) {
throw new \InvalidArgumentException("The fifth argument to " . __METHOD__ . " must be an instance of MigrateLookupInterface.");
}
$this->moduleHandler = $module_handler;
$this->migrationPlugin = $migration_plugin;
$this->migrateLookup = $migrate_lookup;
if (isset($configuration['skip_php'])) {
$this->skipPHP = $configuration['skip_php'];
......@@ -59,18 +94,12 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
$migration_configuration = [
'migration' => [
'd6_user_role',
'd7_user_role',
],
];
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('module_handler'),
$container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_configuration, $migration)
$container->get('migrate.lookup')
);
}
......@@ -94,7 +123,22 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
];
foreach ($roles as $key => $role_id) {
$roles[$key] = $this->migrationPlugin->transform($role_id, $migrate_executable, $row, $destination_property);
// This BC layer is included because if the plugin constructor was
// called in the legacy way with a migration_lookup process plugin, it
// may have been preconfigured with a different migration to look up
// against. While this is unlikely, for maximum BC we will continue to
// use the plugin to do the lookup if it is provided, and support for
// this will be removed in Drupal 9.
if ($this->migrationPlugin) {
$roles[$key] = $this->migrationPlugin->transform($role_id, $migrate_executable, $row, $destination_property);
}
else {
$lookup_result = $this->migrateLookup->lookup(['d6_user_role', 'd7_user_role'], [$role_id]);
if ($lookup_result) {
$roles[$key] = $lookup_result[0]['id'];
}
}
}
$visibility['user_role']['roles'] = array_combine($roles, $roles);
}
......
......@@ -4,8 +4,8 @@
use Drupal\block\Plugin\migrate\process\BlockVisibility;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
/**
......@@ -29,8 +29,8 @@ class BlockVisibilityTest extends MigrateProcessTestCase {
protected function setUp() {
parent::setUp();
$this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
$migration_plugin = $this->prophesize(MigrateProcessInterface::class);
$this->plugin = new BlockVisibility([], 'block_visibility_pages', [], $this->moduleHandler->reveal(), $migration_plugin->reveal());
$migrate_lookup = $this->prophesize(MigrateLookupInterface::class);
$this->plugin = new BlockVisibility([], 'block_visibility_pages', [], $this->moduleHandler->reveal(), $migrate_lookup->reveal());
}
/**
......@@ -86,7 +86,7 @@ public function testTransformPhpDisabled() {
*/
public function testTransformException() {
$this->moduleHandler->moduleExists('php')->willReturn(FALSE);
$migration_plugin = $this->prophesize(MigrateProcessInterface::class);
$migrate_lookup = $this->prophesize(MigrateLookupInterface::class);
$this->row = $this->getMockBuilder('Drupal\migrate\Row')
->disableOriginalConstructor()
->setMethods(['getSourceProperty'])
......@@ -94,7 +94,7 @@ public function testTransformException() {
$this->row->expects($this->exactly(2))
->method('getSourceProperty')
->willReturnMap([['bid', 99], ['module', 'foobar']]);
$this->plugin = new BlockVisibility(['skip_php' => TRUE], 'block_visibility_pages', [], $this->moduleHandler->reveal(), $migration_plugin->reveal());
$this->plugin = new BlockVisibility(['skip_php' => TRUE], 'block_visibility_pages', [], $this->moduleHandler->reveal(), $migrate_lookup->reveal());
$this->expectException(MigrateSkipRowException::class);
$this->expectExceptionMessage("The block with bid '99' from module 'foobar' will have no PHP or request_path visibility configuration.");
$this->plugin->transform([2, '<?php', []], $this->migrateExecutable, $this->row, 'destinationproperty');
......
<?php
namespace Drupal\Tests\block\Unit\Plugin\migrate\process;
use Drupal\block\Plugin\migrate\process\BlockPluginId;
use Drupal\block_content\Entity\BlockContent;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
/**
* Tests legacy usage of BlockPluginId.
*
* @group block
* @group legacy
*
* @coversDefaultClass \Drupal\block\Plugin\migrate\process\BlockPluginId
*/
class LegacyBlockPluginIdTest extends MigrateProcessTestCase {
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$migrate_lookup = $this->prophesize(MigrateLookupInterface::class);
$container = new ContainerBuilder();
$container->set('migrate.lookup', $migrate_lookup->reveal());
\Drupal::setContainer($container);
}
/**
* Tests legacy construction.
*
* @expectedDeprecation Passing a migration process plugin as the fifth argument to Drupal\block\Plugin\migrate\process\BlockPluginId::__construct is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268
*/
public function testConstruct() {
$process_plugin = $this->prophesize(MigrateProcessInterface::class);
$process_plugin->transform(1, $this->migrateExecutable, $this->row, 'destination_property')->willReturn(3);
$block = $this->prophesize(BlockContent::class);
$block->uuid()->willReturn('123456789');
$storage = $this->prophesize(EntityStorageInterface::class);
$storage->load(3)->willReturn($block->reveal());
$plugin = new BlockPluginId([], '', [], $storage->reveal(), $process_plugin->reveal());
$this->assertSame('block_content:123456789', $plugin->transform(['block', 1], $this->migrateExecutable, $this->row, 'destination_property'));
}
}
<?php
namespace Drupal\Tests\block\Unit\Plugin\migrate\process;
use Drupal\block\Plugin\migrate\process\BlockVisibility;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
/**
* Tests the block_visibility process plugin.
*
* @coversDefaultClass \Drupal\block\Plugin\migrate\process\BlockVisibility
*
* @group block
* @group legacy
*/
class LegacyBlockVisibilityTest extends MigrateProcessTestCase {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$migrate_lookup = $this->prophesize(MigrateLookupInterface::class);
$container = new ContainerBuilder();
$container->set('migrate.lookup', $migrate_lookup->reveal());
\Drupal::setContainer($container);
$this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
$migration_plugin = $this->prophesize(MigrateProcessInterface::class);
$this->plugin = new BlockVisibility([], 'block_visibility_pages', [], $this->moduleHandler->reveal(), $migration_plugin->reveal());
}
/**
* Tests Transform.
*
* @covers ::transform
*
* @expectedDeprecation Passing a migration process plugin as the fifth argument to Drupal\block\Plugin\migrate\process\BlockVisibility::__construct is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268
*/
public function testTransformNoData() {
$transformed_value = $this->plugin->transform([0, '', []], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertEmpty($transformed_value);
}
/**
* Tests Transform.
*
* @covers ::transform
*
* @expectedDeprecation Passing a migration process plugin as the fifth argument to Drupal\block\Plugin\migrate\process\BlockVisibility::__construct is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268
*/
public function testTransformSinglePageWithFront() {
$visibility = $this->plugin->transform([0, '<front>', []], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame('request_path', $visibility['request_path']['id']);
$this->assertTrue($visibility['request_path']['negate']);
$this->assertSame('<front>', $visibility['request_path']['pages']);
}
/**
* Tests Transform.
*
* @covers ::transform
*
* @expectedDeprecation Passing a migration process plugin as the fifth argument to Drupal\block\Plugin\migrate\process\BlockVisibility::__construct is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268
*/
public function testTransformMultiplePagesWithFront() {
$visibility = $this->plugin->transform([1, "foo\n/bar\rbaz\r\n<front>", []], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame('request_path', $visibility['request_path']['id']);
$this->assertFalse($visibility['request_path']['negate']);
$this->assertSame("/foo\n/bar\n/baz\n<front>", $visibility['request_path']['pages']);
}
/**
* Tests Transform.
*
* @covers ::transform
*
* @expectedDeprecation Passing a migration process plugin as the fifth argument to Drupal\block\Plugin\migrate\process\BlockVisibility::__construct is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268
*/
public function testTransformPhpEnabled() {
$this->moduleHandler->moduleExists('php')->willReturn(TRUE);
$visibility = $this->plugin->transform([2, '<?php', []], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame('php', $visibility['php']['id']);
$this->assertFalse($visibility['php']['negate']);
$this->assertSame('<?php', $visibility['php']['php']);
}
/**
* Tests Transform.
*
* @covers ::transform
*
* @expectedDeprecation Passing a migration process plugin as the fifth argument to Drupal\block\Plugin\migrate\process\BlockVisibility::__construct is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268
*/
public function testTransformPhpDisabled() {
$this->moduleHandler->moduleExists('php')->willReturn(FALSE);
$transformed_value = $this->plugin->transform([2, '<?php', []], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertEmpty($transformed_value);
}
/**
* Tests Transform.
*
* @covers ::transform
*
* @expectedDeprecation Passing a migration process plugin as the fifth argument to Drupal\block\Plugin\migrate\process\BlockVisibility::__construct is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268
*/
public function testTransformException() {
$this->moduleHandler->moduleExists('php')->willReturn(FALSE);
$migration_plugin = $this->prophesize(MigrateProcessInterface::class);
$this->row = $this->getMockBuilder('Drupal\migrate\Row')
->disableOriginalConstructor()
->setMethods(['getSourceProperty'])
->getMock();
$this->row->expects($this->exactly(2))
->method('getSourceProperty')
->willReturnMap([['bid', 99], ['module', 'foobar']]);
$this->plugin = new BlockVisibility(['skip_php' => TRUE], 'block_visibility_pages', [], $this->moduleHandler->reveal(), $migration_plugin->reveal());
$this->expectException(MigrateSkipRowException::class);
$this->expectExceptionMessage("The block with bid '99' from module 'foobar' will have no PHP or request_path visibility configuration.");
$this->plugin->transform([2, '<?php', []], $this->migrateExecutable, $this->row, 'destinationproperty');
}
}
......@@ -13,7 +13,7 @@ process:
tid: tid
langcode: language
vid:
plugin: migration
plugin: migration_lookup
migration: d6_taxonomy_vocabulary
source: vid
name:
......
......@@ -13,7 +13,7 @@ process:
tid: tid
langcode: language
vid:
plugin: migration
plugin: migration_lookup
migration: d6_taxonomy_vocabulary
source: vid
name: name
......@@ -26,7 +26,7 @@ process:
method: process
source: parent
-
plugin: migration
plugin: migration_lookup
migration: d6_taxonomy_term
parent:
plugin: default_value
......
......@@ -14,7 +14,7 @@ process:
# Use the language from the locales_target table.
langcode: ltlanguage
vid:
plugin: migration
plugin: migration_lookup
migration: d7_taxonomy_vocabulary
source: vid
name:
......
......@@ -25,7 +25,7 @@ process:
tid: tid
langcode: language
vid:
plugin: migration
plugin: migration_lookup
migration: d7_taxonomy_vocabulary
source: vid
name: name
......@@ -39,7 +39,7 @@ process:
method: process
source: parent
-
plugin: migration
plugin: migration_lookup
migration: d7_taxonomy_term
parent:
plugin: default_value
......
......@@ -3,6 +3,7 @@
namespace Drupal\file\Plugin\migrate\process\d6;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\MigrateProcessInterface;
......@@ -21,9 +22,21 @@ class FieldFile extends ProcessPluginBase implements ContainerFactoryPluginInter
* The migration process plugin, configured for lookups in d6_file.
*
* @var \Drupal\migrate\Plugin\MigrateProcessInterface
*
* @deprecated in drupal:8.8.x and is removed from drupal:9.0.0. Use
* the migrate.lookup service instead.
*
* @see https://www.drupal.org/node/3047268
*/
protected $migrationPlugin;
/**
* The migrate lookup service.
*
* @var \Drupal\migrate\MigrateLookupInterface
*/
protected $migrateLookup;
/**
* Constructs a FieldFile plugin instance.
*
......@@ -35,32 +48,36 @@ class FieldFile extends ProcessPluginBase implements ContainerFactoryPluginInter
* The plugin definition.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The current migration.
* @param \Drupal\migrate\Plugin\MigrateProcessInterface $migration_plugin
* An instance of the 'migration' process plugin.
* @param \Drupal\migrate\MigrateLookupInterface $migrate_lookup
* The migrate lookup service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, MigrateProcessInterface $migration_plugin) {
// @codingStandardsIgnoreLine
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, $migrate_lookup) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
if ($migrate_lookup instanceof MigrateProcessInterface) {
@trigger_error('Passing a migration process plugin as the fourth argument to ' . __METHOD__ . ' is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268', E_USER_DEPRECATED);
$this->migrationPlugin = $migrate_lookup;
$migrate_lookup = \Drupal::service('migrate.lookup');
}
elseif (!$migrate_lookup instanceof MigrateLookupInterface) {
throw new \InvalidArgumentException("The fifth argument to " . __METHOD__ . " must be an instance of MigrateLookupInterface.");
}
$this->migration = $migration;
$this->migrationPlugin = $migration_plugin;
$this->migrateLookup = $migrate_lookup;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
// Configure the migration process plugin to look up migrated IDs from
// a d6 file migration.
$migration_plugin_configuration = $configuration + [
'migration' => 'd6_file',
'source' => ['fid'],
];
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$migration,
$container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_plugin_configuration, $migration)
$container->get('migrate.lookup')
);
}
......@@ -75,7 +92,22 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
// some reason -- file migration is notoriously brittle -- and we do NOT
// want to send invalid file references into the field system (it causes
// fatals), so return an empty item instead.
if ($fid = $this->migrationPlugin->transform($value['fid'], $migrate_executable, $row, $destination_property)) {
// This BC layer is included because if the plugin constructor was called
// in the legacy way with a migration_lookup process plugin, it may have
// been preconfigured with a different migration to look up against. While
// this is unlikely, for maximum BC we will continue to use the plugin to do
// the lookup if it is provided, and support for this will be removed in
// Drupal 9.
if ($this->migrationPlugin) {
$fid = $this->migrationPlugin->transform($value['fid'], $migrate_executable, $row, $destination_property);
}
else {
$lookup_result = $this->migrateLookup->lookup('d6_file', [$value['fid']]);
if ($lookup_result) {
$fid = $lookup_result[0]['fid'];
}
}
if (!empty($fid)) {
return [
'target_id' => $fid,
'display' => $value['list'],
......
......@@ -25,8 +25,7 @@ class CckFileTest extends MigrateDrupalTestBase {
public function testConfigurableFileMigration() {
$migration = Migration::create($this->container, [], 'custom_migration', []);
$cck_file_migration = CckFile::create($this->container, ['migration' => 'custom_file'], 'custom_file', [], $migration);
$migration_plugin = $this->readAttribute($cck_file_migration, 'migrationPlugin');
$config = $this->readAttribute($migration_plugin, 'configuration');
$config = $this->readAttribute($cck_file_migration, 'configuration');
$this->assertEquals($config['migration'], 'custom_file');
}
......
......@@ -2,7 +2,9 @@
namespace Drupal\Tests\file\Unit\Plugin\migrate\process\d6;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\file\Plugin\migrate\process\d6\CckFile;
use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\MigrateProcessInterface;
......@@ -21,6 +23,10 @@ class CckFileTest extends UnitTestCase {
* @expectedDeprecation CckFile is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\file\Plugin\migrate\process\d6\FieldFile instead.
*/
public function testTransformAltTitle() {
$migrate_lookup = $this->prophesize(MigrateLookupInterface::class);
$container = new ContainerBuilder();
$container->set('migrate.lookup', $migrate_lookup->reveal());
\Drupal::setContainer($container);
$executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
$row = $this->prophesize(Row::class)->reveal();
$migration = $this->prophesize(MigrationInterface::class)->reveal();
......
......@@ -2,7 +2,9 @@
namespace Drupal\Tests\file\Unit\Plugin\migrate\process\d6;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\file\Plugin\migrate\process\d6\FieldFile;
use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\MigrateProcessInterface;
......@@ -22,6 +24,49 @@ public function testTransformAltTitle() {
$row = $this->prophesize(Row::class)->reveal();
$migration = $this->prophesize(MigrationInterface::class)->reveal();
$migrate_lookup = $this->prophesize(MigrateLookupInterface::class);
$migrate_lookup->lookup('d6_file', [1])->willReturn([['fid' => 1]]);
$plugin = new FieldFile([], 'd6_file', [], $migration, $migrate_lookup->reveal());
$options