Issue #3088480 by phenaproxima, mikelutz, quietone: Remove the "cckfield" plugin type from the migration system
parent
15ba832e67
commit
a74215876a
|
@ -8,7 +8,6 @@ use Drupal\migrate\MigrateExecutableInterface;
|
|||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\process\StaticMap;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
@ -19,13 +18,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
*/
|
||||
class FieldType extends StaticMap implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The cckfield plugin manager.
|
||||
*
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface
|
||||
*/
|
||||
protected $cckPluginManager;
|
||||
|
||||
/**
|
||||
* The field plugin manager.
|
||||
*
|
||||
|
@ -49,16 +41,13 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface {
|
|||
* The plugin ID.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin definition.
|
||||
* @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_plugin_manager
|
||||
* The cckfield plugin manager.
|
||||
* @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_plugin_manager
|
||||
* The field plugin manager.
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration being run.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateCckFieldPluginManagerInterface $cck_plugin_manager, MigrateFieldPluginManagerInterface $field_plugin_manager, MigrationInterface $migration = NULL) {
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateFieldPluginManagerInterface $field_plugin_manager, MigrationInterface $migration = NULL) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->cckPluginManager = $cck_plugin_manager;
|
||||
$this->fieldPluginManager = $field_plugin_manager;
|
||||
$this->migration = $migration;
|
||||
}
|
||||
|
@ -71,7 +60,6 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface {
|
|||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('plugin.manager.migrate.cckfield'),
|
||||
$container->get('plugin.manager.migrate.field'),
|
||||
$migration
|
||||
);
|
||||
|
@ -87,13 +75,7 @@ class FieldType extends StaticMap implements ContainerFactoryPluginInterface {
|
|||
return $this->fieldPluginManager->createInstance($plugin_id, [], $this->migration)->getFieldType($row);
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
try {
|
||||
$plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, [], $this->migration);
|
||||
return $this->cckPluginManager->createInstance($plugin_id, [], $this->migration)->getFieldType($row);
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
return parent::transform($value, $migrate_executable, $row, $destination_property);
|
||||
}
|
||||
return parent::transform($value, $migrate_executable, $row, $destination_property);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ use Drupal\migrate\MigrateExecutableInterface;
|
|||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
@ -44,13 +43,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
*/
|
||||
class ProcessField extends ProcessPluginBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The cckfield plugin manager.
|
||||
*
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface
|
||||
*/
|
||||
protected $cckPluginManager;
|
||||
|
||||
/**
|
||||
* The field plugin manager.
|
||||
*
|
||||
|
@ -74,16 +66,13 @@ class ProcessField extends ProcessPluginBase implements ContainerFactoryPluginIn
|
|||
* The plugin ID.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin definition.
|
||||
* @param \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface $cck_plugin_manager
|
||||
* The cckfield plugin manager.
|
||||
* @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_plugin_manager
|
||||
* The field plugin manager.
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration being run.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateCckFieldPluginManagerInterface $cck_plugin_manager, MigrateFieldPluginManagerInterface $field_plugin_manager, MigrationInterface $migration = NULL) {
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateFieldPluginManagerInterface $field_plugin_manager, MigrationInterface $migration = NULL) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->cckPluginManager = $cck_plugin_manager;
|
||||
$this->fieldPluginManager = $field_plugin_manager;
|
||||
$this->migration = $migration;
|
||||
}
|
||||
|
@ -96,7 +85,6 @@ class ProcessField extends ProcessPluginBase implements ContainerFactoryPluginIn
|
|||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('plugin.manager.migrate.cckfield'),
|
||||
$container->get('plugin.manager.migrate.field'),
|
||||
$migration
|
||||
);
|
||||
|
@ -119,12 +107,7 @@ class ProcessField extends ProcessPluginBase implements ContainerFactoryPluginIn
|
|||
return $this->callMethodOnFieldPlugin($this->fieldPluginManager, $value, $method, $row);
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
try {
|
||||
return $this->callMethodOnFieldPlugin($this->cckPluginManager, $value, $method, $row);
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ use Drupal\migrate\MigrateException;
|
|||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateFieldInterface;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
|
||||
use Drupal\Tests\migrate\Unit\MigrateTestCase;
|
||||
|
@ -26,7 +25,6 @@ class ProcessFieldTest extends MigrateTestCase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->cckFieldManager = $this->prophesize(MigrateCckFieldPluginManagerInterface::class);
|
||||
$this->fieldManager = $this->prophesize(MigrateFieldPluginManagerInterface::class);
|
||||
$this->fieldPlugin = $this->prophesize(MigrateFieldInterface::class);
|
||||
$this->migrateExecutable = $this->prophesize(MigrateExecutable::class);
|
||||
|
@ -60,7 +58,7 @@ class ProcessFieldTest extends MigrateTestCase {
|
|||
if ($method) {
|
||||
$this->fieldPlugin->$method($this->row->reveal())->willReturn($expected_value);
|
||||
}
|
||||
$this->plugin = new ProcessField(['method' => $method], $value, [], $this->cckFieldManager->reveal(), $this->fieldManager->reveal(), $this->migration->reveal());
|
||||
$this->plugin = new ProcessField(['method' => $method], $value, [], $this->fieldManager->reveal(), $this->migration->reveal());
|
||||
|
||||
if ($migrate_exception) {
|
||||
$this->expectException(MigrateException::class);
|
||||
|
@ -69,7 +67,6 @@ class ProcessFieldTest extends MigrateTestCase {
|
|||
|
||||
if ($plugin_not_found) {
|
||||
$exception = new PluginNotFoundException('foo');
|
||||
$this->cckFieldManager->getPluginIdFromFieldType()->willThrow($exception);
|
||||
$this->fieldManager->getPluginIdFromFieldType()->willThrow($exception);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\file\Plugin\migrate\cckfield\d6;
|
||||
|
||||
@trigger_error('FileField is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\file\Plugin\migrate\field\d6\FileField instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "filefield",
|
||||
* core = {6},
|
||||
* source_module = "filefield",
|
||||
* destination_module = "file"
|
||||
* )
|
||||
*
|
||||
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\file\Plugin\migrate\field\d6\FileField instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*/
|
||||
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' => 'd6_cck_file',
|
||||
'source' => $field_name,
|
||||
];
|
||||
$migration->mergeProcessOfProperty($field_name, $process);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldType(Row $row) {
|
||||
return $row->getSourceProperty('widget_type') == 'imagefield_widget' ? 'image' : 'file';
|
||||
}
|
||||
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\file\Plugin\migrate\cckfield\d7;
|
||||
|
||||
@trigger_error('FileField is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\file\Plugin\migrate\field\d7\FileField instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "file",
|
||||
* core = {7},
|
||||
* source_module = "file",
|
||||
* destination_module = "file"
|
||||
* )
|
||||
*
|
||||
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\file\Plugin\migrate\field\d7\FileField instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*/
|
||||
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' => 'sub_process',
|
||||
'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';
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
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\image\Plugin\migrate\field\d7\ImageField instead. See https://www.drupal.org/node/2936061.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\image\Plugin\migrate\cckfield\d7\ImageField as LegacyImageField;
|
||||
|
||||
/**
|
||||
* CCK plugin for image fields.
|
||||
*
|
||||
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\image\Plugin\migrate\field\d7\ImageField instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2936061
|
||||
*/
|
||||
class ImageField extends LegacyImageField {}
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\file\Plugin\migrate\process\d6;
|
||||
|
||||
@trigger_error('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.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "d6_cck_file"
|
||||
* )
|
||||
*
|
||||
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\file\Plugin\migrate\process\d6\FieldFile instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*/
|
||||
class CckFile extends FieldFile {}
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Kernel\Migrate\process\d6;
|
||||
|
||||
use Drupal\file\Plugin\migrate\process\d6\CckFile;
|
||||
use Drupal\migrate\Plugin\Migration;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
|
||||
|
||||
/**
|
||||
* Cck file field migration.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\file\Plugin\migrate\process\d6\CckFile
|
||||
*
|
||||
* @group file
|
||||
* @group legacy
|
||||
*/
|
||||
class CckFileTest extends MigrateDrupalTestBase {
|
||||
|
||||
/**
|
||||
* Tests configurability of file migration name.
|
||||
*
|
||||
* @covers ::__construct
|
||||
* @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 testConfigurableFileMigration() {
|
||||
$migration = Migration::create($this->container, [], 'custom_migration', []);
|
||||
$cck_file_migration = CckFile::create($this->container, ['migration' => 'custom_file'], 'custom_file', [], $migration);
|
||||
$config = $this->readAttribute($cck_file_migration, 'configuration');
|
||||
|
||||
$this->assertEquals($config['migration'], 'custom_file');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Unit\Plugin\migrate\cckfield\d6;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\file\Plugin\migrate\cckfield\d6\FileField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\file\Plugin\migrate\cckfield\d6\FileField
|
||||
* @group file
|
||||
* @group legacy
|
||||
*/
|
||||
class FileCckTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new FileField([], 'file', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's defineValueProcessPipeline() 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 ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessCckFieldValues() {
|
||||
$this->plugin->processCckFieldValues($this->migration, 'somefieldname', []);
|
||||
|
||||
$expected = [
|
||||
'plugin' => 'd6_cck_file',
|
||||
'source' => 'somefieldname',
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetFieldType().
|
||||
*/
|
||||
public function getFieldTypeProvider() {
|
||||
return [
|
||||
['image', 'imagefield_widget'],
|
||||
['file', 'filefield_widget'],
|
||||
['file', 'x_widget'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFieldType
|
||||
* @dataProvider getFieldTypeProvider
|
||||
*/
|
||||
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
|
||||
$row = new Row();
|
||||
$row->setSourceProperty('widget_type', $widget_type);
|
||||
$row->setSourceProperty('global_settings', $settings);
|
||||
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Unit\Plugin\migrate\cckfield\d7;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\file\Plugin\migrate\cckfield\d7\FileField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\file\Plugin\migrate\cckfield\d7\FileField
|
||||
* @group file
|
||||
* @group legacy
|
||||
*/
|
||||
class FileCckTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new FileField([], 'file', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's defineValueProcessPipeline() 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 ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessCckFieldValues() {
|
||||
$this->plugin->processCckFieldValues($this->migration, 'somefieldname', []);
|
||||
|
||||
$expected = [
|
||||
'plugin' => 'sub_process',
|
||||
'source' => 'somefieldname',
|
||||
'process' => [
|
||||
'target_id' => 'fid',
|
||||
'display' => 'display',
|
||||
'description' => 'description',
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetFieldType().
|
||||
*/
|
||||
public function getFieldTypeProvider() {
|
||||
return [
|
||||
['image', 'imagefield_widget'],
|
||||
['file', 'filefield_widget'],
|
||||
['file', 'x_widget'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFieldType
|
||||
* @dataProvider getFieldTypeProvider
|
||||
*/
|
||||
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
|
||||
$row = new Row();
|
||||
$row->setSourceProperty('widget_type', $widget_type);
|
||||
$row->setSourceProperty('global_settings', $settings);
|
||||
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\file\Unit\Plugin\migrate\cckfield\d7;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\file\Plugin\migrate\cckfield\d7\ImageField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\file\Plugin\migrate\cckfield\d7\ImageField
|
||||
* @group file
|
||||
* @group legacy
|
||||
*/
|
||||
class ImageCckTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new ImageField([], 'image', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's defineValueProcessPipeline() 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 ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessCckFieldValues() {
|
||||
$this->plugin->processCckFieldValues($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());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
<?php
|
||||
|
||||
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;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @group file
|
||||
* @group legacy
|
||||
*/
|
||||
class CckFileTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Tests that alt and title attributes are included in transformed values.
|
||||
*
|
||||
* @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();
|
||||
|
||||
$migration_plugin = $this->prophesize(MigrateProcessInterface::class);
|
||||
$migration_plugin->transform(1, $executable, $row, 'foo')->willReturn(1);
|
||||
|
||||
$plugin = new CckFile([], 'd6_cck_file', [], $migration, $migration_plugin->reveal());
|
||||
|
||||
$options = [
|
||||
'alt' => 'Foobaz',
|
||||
'title' => 'Wambooli',
|
||||
];
|
||||
$value = [
|
||||
'fid' => 1,
|
||||
'list' => TRUE,
|
||||
'data' => serialize($options),
|
||||
];
|
||||
|
||||
$transformed = $plugin->transform($value, $executable, $row, 'foo');
|
||||
$expected = [
|
||||
'target_id' => 1,
|
||||
'display' => TRUE,
|
||||
'description' => '',
|
||||
'alt' => 'Foobaz',
|
||||
'title' => 'Wambooli',
|
||||
];
|
||||
$this->assertSame($expected, $transformed);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\image\Plugin\migrate\cckfield\d7;
|
||||
|
||||
@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.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "image",
|
||||
* core = {7},
|
||||
* source_module = "image",
|
||||
* destination_module = "file"
|
||||
* )
|
||||
*
|
||||
* @deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\image\Plugin\migrate\field\d7\ImageField instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\link\Plugin\migrate\cckfield;
|
||||
|
||||
@trigger_error('LinkField is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\link\Plugin\migrate\field\d6\LinkField instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "link",
|
||||
* core = {6},
|
||||
* type_map = {
|
||||
* "link_field" = "link"
|
||||
* },
|
||||
* source_module = "link",
|
||||
* destination_module = "link"
|
||||
* )
|
||||
*
|
||||
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\link\Plugin\migrate\field\d6\LinkField instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*/
|
||||
class LinkField extends CckFieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {
|
||||
// See d6_field_formatter_settings.yml and FieldPluginBase
|
||||
// alterFieldFormatterMigration().
|
||||
return [
|
||||
'default' => 'link',
|
||||
'plain' => 'link',
|
||||
'absolute' => 'link',
|
||||
'title_plain' => 'link',
|
||||
'url' => 'link',
|
||||
'short' => 'link',
|
||||
'label' => 'link',
|
||||
'separate' => 'link_separate',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
|
||||
$process = [
|
||||
'plugin' => 'd6_cck_link',
|
||||
'source' => $field_name,
|
||||
];
|
||||
$migration->mergeProcessOfProperty($field_name, $process);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\link\Plugin\migrate\cckfield\d7;
|
||||
|
||||
@trigger_error('LinkField is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\link\Plugin\migrate\field\d7\LinkField instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\link\Plugin\migrate\cckfield\LinkField as D6LinkField;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "link_field",
|
||||
* core = {7},
|
||||
* type_map = {
|
||||
* "link_field" = "link"
|
||||
* },
|
||||
* source_module = "link",
|
||||
* destination_module = "link"
|
||||
* )
|
||||
*
|
||||
* This plugin provides the exact same functionality as the Drupal 6 "link"
|
||||
* plugin with the exception that the plugin ID "link_field" is used in the
|
||||
* field type map.
|
||||
*
|
||||
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\link\Plugin\migrate\field\d7\LinkField instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*/
|
||||
class LinkField extends D6LinkField {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldWidgetMap() {
|
||||
// By default, use the plugin ID for the widget types.
|
||||
return ['link_field' => 'link_default'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc}
|
||||
*/
|
||||
public function alterFieldInstanceMigration(MigrationInterface $migration) {
|
||||
$process = [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'settings/title',
|
||||
'bypass' => TRUE,
|
||||
'map' => [
|
||||
'disabled' => DRUPAL_DISABLED,
|
||||
'optional' => DRUPAL_OPTIONAL,
|
||||
'required' => DRUPAL_REQUIRED,
|
||||
],
|
||||
];
|
||||
$migration->mergeProcessOfProperty('settings/title', $process);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\link\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\link\Plugin\migrate\process\FieldLink;
|
||||
|
||||
@trigger_error('CckLink is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\link\Plugin\migrate\process\FieldLink instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "d6_cck_link"
|
||||
* )
|
||||
*
|
||||
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\link\Plugin\migrate\process\FieldLink instead.
|
||||
*/
|
||||
class CckLink extends FieldLink {}
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\link\Kernel\Plugin\migrate\cckfield\d7;
|
||||
|
||||
/**
|
||||
* @group link
|
||||
* @group legacy
|
||||
*/
|
||||
class LinkCckDeprecationTest extends LinkCckTest {
|
||||
|
||||
/**
|
||||
* @expectedDeprecation Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use alterFieldInstanceMigration() instead. See https://www.drupal.org/node/2944598.
|
||||
*/
|
||||
public function testAlterFieldInstanceMigration($method = 'processFieldInstance') {
|
||||
parent::testAlterFieldInstanceMigration($method);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\link\Kernel\Plugin\migrate\cckfield\d7;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\link\Plugin\migrate\cckfield\d7\LinkField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\link\Plugin\migrate\cckfield\d7\LinkField
|
||||
* @group link
|
||||
* @group legacy
|
||||
*/
|
||||
class LinkCckTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['system'];
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->plugin = new LinkField([], 'link', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's alterFieldInstanceMigration() 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 ::alterFieldInstanceMigration
|
||||
*/
|
||||
public function testAlterFieldInstanceMigration($method = 'alterFieldInstanceMigration') {
|
||||
$this->plugin->$method($this->migration);
|
||||
|
||||
$expected = [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'settings/title',
|
||||
'bypass' => TRUE,
|
||||
'map' => [
|
||||
'disabled' => DRUPAL_DISABLED,
|
||||
'optional' => DRUPAL_OPTIONAL,
|
||||
'required' => DRUPAL_REQUIRED,
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\link\Unit\Plugin\migrate\cckfield;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\link\Plugin\migrate\cckfield\LinkField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\link\Plugin\migrate\cckfield\LinkField
|
||||
* @group link
|
||||
* @group legacy
|
||||
*/
|
||||
class LinkCckTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new LinkField([], 'link', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's processCckFieldValues() 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 ::processCckFieldValues
|
||||
* @expectedDeprecation LinkField is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\link\Plugin\migrate\field\d6\LinkField instead.
|
||||
*/
|
||||
public function testProcessCckFieldValues() {
|
||||
$this->plugin->processCckFieldValues($this->migration, 'somefieldname', []);
|
||||
|
||||
$expected = [
|
||||
'plugin' => 'd6_cck_link',
|
||||
'source' => 'somefieldname',
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess());
|
||||
}
|
||||
|
||||
}
|
|
@ -7,15 +7,6 @@ services:
|
|||
- '@cache.discovery'
|
||||
- '@module_handler'
|
||||
- '\Drupal\migrate_drupal\Annotation\MigrateField'
|
||||
plugin.manager.migrate.cckfield:
|
||||
class: Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManager
|
||||
arguments:
|
||||
- cckfield
|
||||
- '@container.namespaces'
|
||||
- '@cache.discovery'
|
||||
- '@module_handler'
|
||||
- '\Drupal\migrate_drupal\Annotation\MigrateCckField'
|
||||
deprecated: The "%service_id%" service is deprecated. You should use the 'plugin.manager.migrate.field' service instead. See https://www.drupal.org/node/2751897
|
||||
logger.channel.migrate_drupal:
|
||||
parent: logger.channel_base
|
||||
arguments: ['migrate_drupal']
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Annotation;
|
||||
|
||||
@trigger_error('MigrateCckField is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Deprecated: Defines a cckfield plugin annotation object.
|
||||
*
|
||||
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\migrate_drupal\Annotation\MigrateField instead.
|
||||
*
|
||||
* Plugin Namespace: Plugin\migrate\cckfield
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class MigrateCckField extends MigrateField {
|
||||
|
||||
}
|
|
@ -8,10 +8,10 @@ use Drupal\Component\Annotation\Plugin;
|
|||
* Defines a field plugin annotation object.
|
||||
*
|
||||
* Field plugins are responsible for handling the migration of custom fields
|
||||
* (provided by CCK in Drupal 6 and Field API in Drupal 7) to Drupal 8. They are
|
||||
* allowed to alter fieldable entity migrations when these migrations are being
|
||||
* generated, and can compute destination field types for individual fields
|
||||
* during the actual migration process.
|
||||
* (provided by Field API in Drupal 7) to Drupal 8. They are allowed to alter
|
||||
* fieldable entity migrations when these migrations are being generated, and
|
||||
* can compute destination field types for individual fields during the actual
|
||||
* migration process.
|
||||
*
|
||||
* Plugin Namespace: Plugin\migrate\field
|
||||
*
|
||||
|
|
|
@ -8,7 +8,6 @@ use Drupal\migrate\Exception\RequirementsException;
|
|||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
|
||||
use Drupal\migrate\Plugin\RequirementsInterface;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
|
||||
|
||||
/**
|
||||
|
@ -16,13 +15,6 @@ use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
|
|||
*/
|
||||
class FieldDiscovery implements FieldDiscoveryInterface {
|
||||
|
||||
/**
|
||||
* The CCK plugin manager.
|
||||
*
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface
|
||||
*/
|
||||
protected $cckPluginManager;
|
||||
|
||||
/**
|
||||
* An array of already discovered field plugin information.
|
||||
*
|
||||
|
@ -153,12 +145,6 @@ class FieldDiscovery implements FieldDiscoveryInterface {
|
|||
if ($plugin) {
|
||||
$method = isset($plugin_definition['field_plugin_method']) ? $plugin_definition['field_plugin_method'] : 'defineValueProcessPipeline';
|
||||
|
||||
// @todo Remove the following 3 lines of code prior to Drupal 9.0.0.
|
||||
// https://www.drupal.org/node/3032317
|
||||
if ($plugin instanceof MigrateCckFieldInterface) {
|
||||
$method = isset($plugin_definition['cck_plugin_method']) ? $plugin_definition['cck_plugin_method'] : 'processCckFieldValues';
|
||||
}
|
||||
|
||||
call_user_func_array([
|
||||
$plugin,
|
||||
$method,
|
||||
|
@ -170,7 +156,7 @@ class FieldDiscovery implements FieldDiscoveryInterface {
|
|||
}
|
||||
else {
|
||||
// Default to a get process plugin if this is a value migration.
|
||||
if ((empty($plugin_definition['field_plugin_method']) || $plugin_definition['field_plugin_method'] === 'defineValueProcessPipeline') && (empty($plugin_definition['cck_plugin_method']) || $plugin_definition['cck_plugin_method'] === 'processCckFieldValues')) {
|
||||
if ((empty($plugin_definition['field_plugin_method']) || $plugin_definition['field_plugin_method'] === 'defineValueProcessPipeline')) {
|
||||
$migration->setProcessOfProperty($field_name, $field_name);
|
||||
}
|
||||
}
|
||||
|
@ -185,8 +171,8 @@ class FieldDiscovery implements FieldDiscoveryInterface {
|
|||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration to retrieve the plugin for.
|
||||
*
|
||||
* @return \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface|\Drupal\migrate_drupal\Plugin\MigrateFieldInterface|bool
|
||||
* The appropriate field or cck plugin to process this field type.
|
||||
* @return \Drupal\migrate_drupal\Plugin\MigrateFieldInterface|bool
|
||||
* The appropriate field plugin to process this field type.
|
||||
*
|
||||
* @throws \Drupal\Component\Plugin\Exception\PluginException
|
||||
* @throws \InvalidArgumentException
|
||||
|
@ -199,17 +185,7 @@ class FieldDiscovery implements FieldDiscoveryInterface {
|
|||
$plugin = $this->fieldPluginManager->createInstance($plugin_id, ['core' => $core], $migration);
|
||||
}
|
||||
catch (PluginNotFoundException $ex) {
|
||||
// @todo Replace try/catch block with $plugin = FALSE for Drupal 9.
|
||||
// https://www.drupal.org/project/drupal/issues/3033733
|
||||
try {
|
||||
/** @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManager $cck_plugin_manager */
|
||||
$cck_plugin_manager = $this->getCckPluginManager();
|
||||
$plugin_id = $cck_plugin_manager->getPluginIdFromFieldType($field_type, ['core' => $core], $migration);
|
||||
$plugin = $cck_plugin_manager->createInstance($plugin_id, ['core' => $core], $migration);
|
||||
}
|
||||
catch (PluginNotFoundException $ex) {
|
||||
$plugin = FALSE;
|
||||
}
|
||||
$plugin = FALSE;
|
||||
}
|
||||
$this->fieldPluginCache[$core][$field_type] = $plugin;
|
||||
}
|
||||
|
@ -289,23 +265,6 @@ class FieldDiscovery implements FieldDiscoveryInterface {
|
|||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the deprecated CCK Plugin Manager service as a BC shim.
|
||||
*
|
||||
* We don't inject this service directly because it is deprecated, and we
|
||||
* don't want to instantiate the plugin manager unless we have to, to avoid
|
||||
* triggering deprecation errors.
|
||||
*
|
||||
* @return \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface
|
||||
* The CCK Plugin Manager.
|
||||
*/
|
||||
protected function getCckPluginManager() {
|
||||
if (!$this->cckPluginManager) {
|
||||
$this->cckPluginManager = \Drupal::service('plugin.manager.migrate.cckfield');
|
||||
}
|
||||
return $this->cckPluginManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the source plugin to use to gather field information.
|
||||
*
|
||||
|
@ -327,10 +286,10 @@ class FieldDiscovery implements FieldDiscoveryInterface {
|
|||
}
|
||||
catch (RequirementsException $e) {
|
||||
// If checkRequirements() failed, the source database did not support
|
||||
// fields (i.e., CCK is not installed in D6 or Field is not installed in
|
||||
// D7). Therefore, $fields will be empty and below we'll return an empty
|
||||
// array. The migration will proceed without adding fields.
|
||||
$this->logger->notice('Field discovery failed for Drupal core version @core. Did this site have the CCK or Field module installed? Error: @message', [
|
||||
// fields (i.e., Field is not installed in D7). Therefore, $fields will
|
||||
// be empty and below we'll return an empty array. The migration will
|
||||
// proceed without adding fields.
|
||||
$this->logger->notice('Field discovery failed for Drupal core version @core. Did this site have the Field module installed? Error: @message', [
|
||||
'@core' => $core,
|
||||
'@message' => $e->getMessage(),
|
||||
]);
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin;
|
||||
|
||||
@trigger_error('MigrateCckFieldInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for all CCK field type plugins.
|
||||
*
|
||||
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\migrate_drupal\Annotation\MigrateField instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*/
|
||||
interface MigrateCckFieldInterface extends MigrateFieldInterface {
|
||||
|
||||
/**
|
||||
* Apply any custom processing to the cck bundle migrations.
|
||||
*
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration entity.
|
||||
* @param string $field_name
|
||||
* The field name we're processing the value for.
|
||||
* @param array $data
|
||||
* The array of field data from CckFieldValues::fieldData().
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data);
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin;
|
||||
|
||||
@trigger_error('MigrateCckFieldPluginManager is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateFieldPluginManager instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Deprecated: Plugin manager for migrate field plugins.
|
||||
*
|
||||
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManager instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*
|
||||
* @ingroup migration
|
||||
*/
|
||||
class MigrateCckFieldPluginManager extends MigrateFieldPluginManager implements MigrateCckFieldPluginManagerInterface {}
|
|
@ -1,15 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin;
|
||||
|
||||
@trigger_error('MigrateCckFieldPluginManagerInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateFieldPluginManagerInterface instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Provides an interface for cck field plugin manager.
|
||||
*
|
||||
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*/
|
||||
interface MigrateCckFieldPluginManagerInterface extends MigrateFieldPluginManagerInterface {}
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate;
|
||||
|
||||
@trigger_error('CckMigration is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Plugin\migrate\FieldMigration instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Migration plugin class for migrations dealing with CCK field values.
|
||||
*
|
||||
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\migrate_drupal\Plugin\migrate\FieldMigration instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*/
|
||||
class CckMigration extends FieldMigration {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
const PLUGIN_METHOD = 'cck_plugin_method';
|
||||
|
||||
}
|
|
@ -18,9 +18,7 @@ class FieldMigration extends Migration implements ContainerFactoryPluginInterfac
|
|||
/**
|
||||
* Defines which configuration option has the migration processing function.
|
||||
*
|
||||
* Default method is 'field_plugin_method'. For backwards compatibility,
|
||||
* this constant is overridden in the CckMigration class, in order to
|
||||
* fallback to the old 'cck_plugin_method'.
|
||||
* Default method is 'field_plugin_method'.
|
||||
*
|
||||
* @const string
|
||||
* @deprecated in drupal:8.7.0 and is removed from drupal:9.0.0. Use the migrate_drupal.field_discovery service instead. See https://www.drupal.org/node/3006076.
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_drupal\Plugin\migrate\cckfield;
|
||||
|
||||
@trigger_error('CckFieldPluginBase is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface;
|
||||
|
||||
/**
|
||||
* The base class for all field plugins.
|
||||
*
|
||||
* @deprecated in drupal:8.4.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*
|
||||
* @ingroup migration
|
||||
*/
|
||||
abstract class CckFieldPluginBase extends FieldPluginBase implements MigrateCckFieldInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) {
|
||||
// Provide a bridge to the old method declared on the interface and now an
|
||||
// abstract method in this class.
|
||||
return $this->processCckFieldValues($migration, $field_name, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply any custom processing to the field bundle migrations.
|
||||
*
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* The migration entity.
|
||||
* @param string $field_name
|
||||
* The field name we're processing the value for.
|
||||
* @param array $data
|
||||
* The array of field data from FieldValues::fieldData().
|
||||
*/
|
||||
abstract public function processCckFieldValues(MigrationInterface $migration, $field_name, $data);
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
name: 'Migrate cck field plugin manager test'
|
||||
type: module
|
||||
description: 'Example module demonstrating the cck field plugin manager in the Migrate API.'
|
||||
package: Testing
|
||||
version: VERSION
|
|
@ -1,14 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Module for Migrate CCK Field Plugin Manager testing.
|
||||
*/
|
||||
|
||||
use Drupal\migrate_cckfield_plugin_manager_test\Plugin\migrate\cckfield\D6FileField;
|
||||
|
||||
function migrate_cckfield_plugin_manager_test_migrate_field_info_alter(array &$definitions) {
|
||||
if (isset($definitions['filefield'])) {
|
||||
$definitions['filefield']['class'] = D6FileField::class;
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_cckfield_plugin_manager_test\Plugin\migrate\cckfield;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "d6_file",
|
||||
* core = {6},
|
||||
* type_map = {
|
||||
* "file" = "file"
|
||||
* },
|
||||
* source_module = "foo",
|
||||
* destination_module = "bar"
|
||||
* )
|
||||
*/
|
||||
class D6FileField extends CckFieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
|
||||
$migration->setProcessOfProperty($field_name, [
|
||||
'class' => static::class,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_cckfield_plugin_manager_test\Plugin\migrate\cckfield;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "d6_no_core_version_specified",
|
||||
* source_module = "foo",
|
||||
* destination_module = "bar",
|
||||
* )
|
||||
*/
|
||||
class D6NoCoreVersionSpecified extends CckFieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {}
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel;
|
||||
|
||||
use Drupal\migrate_cckfield_plugin_manager_test\Plugin\migrate\cckfield\D6FileField;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* @group migrate_drupal
|
||||
* @group legacy
|
||||
*/
|
||||
class CckFieldBackwardsCompatibilityTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['file', 'migrate_cckfield_plugin_manager_test'];
|
||||
|
||||
/**
|
||||
* Ensures that the cckfield backwards compatibility layer is invoked.
|
||||
*
|
||||
* @expectedDeprecation MigrateCckFieldInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.
|
||||
*/
|
||||
public function testBackwardsCompatibility() {
|
||||
$migration = $this->container
|
||||
->get('plugin.manager.migration')
|
||||
->getDefinition('d6_node:story');
|
||||
|
||||
$this->assertSame(D6FileField::class, $migration['process']['field_test_filefield']['class']);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
|
||||
/**
|
||||
* Tests the cck field plugin manager.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class MigrateCckFieldPluginManagerTest extends MigrateDrupalTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['system', 'user', 'field', 'migrate_drupal', 'options', 'file', 'text', 'migrate_cckfield_plugin_manager_test'];
|
||||
|
||||
/**
|
||||
* Tests that the correct MigrateCckField plugins are used.
|
||||
*/
|
||||
public function testPluginSelection() {
|
||||
$plugin_manager = \Drupal::service('plugin.manager.migrate.cckfield');
|
||||
|
||||
$this->assertSame('d6_file', $plugin_manager->getPluginIdFromFieldType('file', ['core' => 6]));
|
||||
|
||||
try {
|
||||
// If this test passes, getPluginIdFromFieldType will raise a
|
||||
// PluginNotFoundException and we'll never reach fail().
|
||||
$plugin_manager->getPluginIdFromFieldType('d6_file', ['core' => 7]);
|
||||
$this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
$this->assertSame($e->getMessage(), "Plugin ID 'd6_file' was not found.");
|
||||
}
|
||||
|
||||
// Test fallback when no core version is specified.
|
||||
$this->assertSame('d6_no_core_version_specified', $plugin_manager->getPluginIdFromFieldType('d6_no_core_version_specified', ['core' => 6]));
|
||||
|
||||
try {
|
||||
// If this test passes, getPluginIdFromFieldType will raise a
|
||||
// PluginNotFoundException and we'll never reach fail().
|
||||
$plugin_manager->getPluginIdFromFieldType('d6_no_core_version_specified', ['core' => 7]);
|
||||
$this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
$this->assertSame($e->getMessage(), "Plugin ID 'd6_no_core_version_specified' was not found.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -3,11 +3,8 @@
|
|||
namespace Drupal\Tests\migrate_drupal\Kernel\d7;
|
||||
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
use Drupal\field\Plugin\migrate\source\d7\FieldInstance;
|
||||
use Drupal\migrate_drupal\FieldDiscovery;
|
||||
use Drupal\migrate_drupal\FieldDiscoveryInterface;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\Tests\migrate_drupal\Traits\FieldDiscoveryTestTrait;
|
||||
|
@ -308,59 +305,4 @@ class FieldDiscoveryTest extends MigrateDrupal7TestBase {
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the fallback to deprecated CCK Plugin Manager.
|
||||
*
|
||||
* @covers ::getCckPluginManager
|
||||
* @group legacy
|
||||
* @expectedDeprecation TextField is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\text\Plugin\migrate\field\d6\TextField or \Drupal\text\Plugin\migrate\field\d7\TextField instead.
|
||||
* @expectedDeprecation CckFieldPluginBase is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase instead.
|
||||
* @expectedDeprecation MigrateCckFieldInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.
|
||||
*/
|
||||
public function testGetCckPluginManager() {
|
||||
$definition = [
|
||||
'migration_tags' => ['Drupal 7'],
|
||||
];
|
||||
$migration = $this->migrationPluginManager->createStubMigration($definition);
|
||||
$field_plugin_manager = $this->prophesize(MigrateFieldPluginManagerInterface::class);
|
||||
$field_plugin_manager->getPluginIdFromFieldType('text_long', ['core' => '7'], $migration)->willThrow(PluginNotFoundException::class);
|
||||
$field_discovery = new FieldDiscovery($field_plugin_manager->reveal(), $this->migrationPluginManager, $this->logger);
|
||||
$field_discovery->addBundleFieldProcesses($migration, 'comment', 'comment_node_page');
|
||||
$actual_process = $migration->getProcess();
|
||||
$expected_process = [
|
||||
'comment_body' => [
|
||||
0 => [
|
||||
'plugin' => 'sub_process',
|
||||
'source' => 'comment_body',
|
||||
'process' => [
|
||||
'value' => 'value',
|
||||
'format' => [
|
||||
0 => [
|
||||
'plugin' => 'static_map',
|
||||
'bypass' => TRUE,
|
||||
'source' => 'format',
|
||||
'map' => [
|
||||
0 => NULL,
|
||||
],
|
||||
],
|
||||
1 => [
|
||||
'plugin' => 'skip_on_empty',
|
||||
'method' => 'process',
|
||||
],
|
||||
2 => [
|
||||
'plugin' => 'migration',
|
||||
'migration' => [
|
||||
0 => 'd6_filter_format',
|
||||
1 => 'd7_filter_format',
|
||||
],
|
||||
'source' => 'format',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expected_process, $actual_process);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -292,24 +292,6 @@ class Node extends DrupalSqlBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves raw field data for a node.
|
||||
*
|
||||
* @deprecated in drupal:8.2.0 and is removed from drupal:9.0.0. Use
|
||||
* getFieldData() instead.
|
||||
*
|
||||
* @param array $field
|
||||
* A field and instance definition from getFieldInfo().
|
||||
* @param \Drupal\migrate\Row $node
|
||||
* The node.
|
||||
*
|
||||
* @return array
|
||||
* The field values, keyed by delta.
|
||||
*/
|
||||
protected function getCckData(array $field, Row $node) {
|
||||
return $this->getFieldData($field, $node);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -1,141 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\text\Plugin\migrate\cckfield;
|
||||
|
||||
@trigger_error('TextField is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\text\Plugin\migrate\field\d6\TextField or \Drupal\text\Plugin\migrate\field\d7\TextField instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "text",
|
||||
* type_map = {
|
||||
* "text" = "text",
|
||||
* "text_long" = "text_long",
|
||||
* "text_with_summary" = "text_with_summary"
|
||||
* },
|
||||
* core = {6,7},
|
||||
* source_module = "text",
|
||||
* destination_module = "text",
|
||||
* )
|
||||
*
|
||||
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\text\Plugin\migrate\field\d6\TextField or
|
||||
* \Drupal\text\Plugin\migrate\field\d7\TextField instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*/
|
||||
class TextField extends CckFieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldWidgetMap() {
|
||||
return [
|
||||
'text_textfield' => 'text_textfield',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {
|
||||
return [
|
||||
'default' => 'text_default',
|
||||
'trimmed' => 'text_trimmed',
|
||||
'plain' => 'basic_string',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $field_info) {
|
||||
$widget_type = isset($field_info['widget_type']) ? $field_info['widget_type'] : $field_info['widget']['type'];
|
||||
|
||||
if ($widget_type == 'optionwidgets_onoff') {
|
||||
$process = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
$checked_value = explode("\n", $field_info['global_settings']['allowed_values'])[1];
|
||||
if (strpos($checked_value, '|') !== FALSE) {
|
||||
$checked_value = substr($checked_value, 0, strpos($checked_value, '|'));
|
||||
}
|
||||
$process['value']['map'][$checked_value] = 1;
|
||||
}
|
||||
else {
|
||||
// See \Drupal\migrate_drupal\Plugin\migrate\source\d6\User::baseFields(),
|
||||
// signature_format for an example of the YAML that represents this
|
||||
// process array.
|
||||
$process = [
|
||||
'value' => 'value',
|
||||
'format' => [
|
||||
[
|
||||
'plugin' => 'static_map',
|
||||
'bypass' => TRUE,
|
||||
'source' => 'format',
|
||||
'map' => [0 => NULL],
|
||||
],
|
||||
[
|
||||
'plugin' => 'skip_on_empty',
|
||||
'method' => 'process',
|
||||
],
|
||||
[
|
||||
'plugin' => 'migration',
|
||||
'migration' => [
|
||||
'd6_filter_format',
|
||||
'd7_filter_format',
|
||||
],
|
||||
'source' => 'format',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$process = [
|
||||
'plugin' => 'sub_process',
|
||||
'source' => $field_name,
|
||||
'process' => $process,
|
||||
];
|
||||
$migration->setProcessOfProperty($field_name, $process);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldType(Row $row) {
|
||||
$widget_type = $row->getSourceProperty('widget_type');
|
||||
$settings = $row->getSourceProperty('global_settings');
|
||||
|
||||
if ($widget_type == 'text_textfield') {
|
||||
$field_type = $settings['text_processing'] ? 'text' : 'string';
|
||||
if (empty($settings['max_length']) || $settings['max_length'] > 255) {
|
||||
$field_type .= '_long';
|
||||
}
|
||||
return $field_type;
|
||||
}
|
||||
|
||||
if ($widget_type == 'text_textarea') {
|
||||
$field_type = $settings['text_processing'] ? 'text_long' : 'string_long';
|
||||
return $field_type;
|
||||
}
|
||||
|
||||
switch ($widget_type) {
|
||||
case 'optionwidgets_buttons':
|
||||
case 'optionwidgets_select':
|
||||
return 'list_string';
|
||||
case 'optionwidgets_onoff':
|
||||
return 'boolean';
|
||||
default:
|
||||
return parent::getFieldType($row);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,167 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\text\Unit\Migrate;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\text\Plugin\migrate\cckfield\TextField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\text\Plugin\migrate\cckfield\TextField
|
||||
* @group text
|
||||
* @group legacy
|
||||
*/
|
||||
class TextCckTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new TextField([], 'text', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's processCckFieldValues() method will call
|
||||
// setProcessOfProperty() 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 setProcessOfProperty().
|
||||
$migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
|
||||
->will(function ($arguments) use ($migration) {
|
||||
$migration->getProcess()->willReturn($arguments[1]);
|
||||
});
|
||||
|
||||
$this->migration = $migration->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessFilteredTextFieldValues() {
|
||||
$field_info = [
|
||||
'widget_type' => 'text_textfield',
|
||||
];
|
||||
$this->plugin->processCckFieldValues($this->migration, 'body', $field_info);
|
||||
|
||||
$process = $this->migration->getProcess();
|
||||
$this->assertSame('sub_process', $process['plugin']);
|
||||
$this->assertSame('body', $process['source']);
|
||||
$this->assertSame('value', $process['process']['value']);
|
||||
|
||||
// Ensure that filter format IDs will be looked up in the filter format
|
||||
// migrations.
|
||||
$lookup = $process['process']['format'][2];
|
||||
$this->assertSame('migration', $lookup['plugin']);
|
||||
$this->assertContains('d6_filter_format', $lookup['migration']);
|
||||
$this->assertContains('d7_filter_format', $lookup['migration']);
|
||||
$this->assertSame('format', $lookup['source']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessBooleanTextImplicitValues() {
|
||||
$info = [
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo\nbar",
|
||||
],
|
||||
];
|
||||
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
'map' => [
|
||||
'bar' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess()['process']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessBooleanTextExplicitValues() {
|
||||
$info = [
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo|Foo\nbaz|Baz",
|
||||
],
|
||||
];
|
||||
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
'map' => [
|
||||
'baz' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess()['process']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetFieldType().
|
||||
*/
|
||||
public function getFieldTypeProvider() {
|
||||
return [
|
||||
['string_long', 'text_textfield', ['text_processing' => FALSE]],
|
||||
['string', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 128,
|
||||
],
|
||||
],
|
||||
['string_long', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 4096,
|
||||
],
|
||||
],
|
||||
['text_long', 'text_textfield', ['text_processing' => TRUE]],
|
||||
['text', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 128,
|
||||
],
|
||||
],
|
||||
['text_long', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 4096,
|
||||
],
|
||||
],
|
||||
['list_string', 'optionwidgets_buttons'],
|
||||
['list_string', 'optionwidgets_select'],
|
||||
['boolean', 'optionwidgets_onoff'],
|
||||
['text_long', 'text_textarea', ['text_processing' => TRUE]],
|
||||
['string_long', 'text_textarea', ['text_processing' => FALSE]],
|
||||
[NULL, 'undefined'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFieldType
|
||||
* @dataProvider getFieldTypeProvider
|
||||
*/
|
||||
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
|
||||
$row = new Row(['widget_type' => $widget_type], ['widget_type' => []]);
|
||||
$row->setSourceProperty('global_settings', $settings);
|
||||
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,167 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\text\Unit\Plugin\migrate\cckfield;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\text\Plugin\migrate\cckfield\TextField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\text\Plugin\migrate\cckfield\TextField
|
||||
* @group text
|
||||
* @group legacy
|
||||
*/
|
||||
class TextCckTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new TextField([], 'text', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's processCckFieldValues() method will call
|
||||
// setProcessOfProperty() 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 setProcessOfProperty().
|
||||
$migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
|
||||
->will(function ($arguments) use ($migration) {
|
||||
$migration->getProcess()->willReturn($arguments[1]);
|
||||
});
|
||||
|
||||
$this->migration = $migration->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessFilteredTextFieldValues() {
|
||||
$field_info = [
|
||||
'widget_type' => 'text_textfield',
|
||||
];
|
||||
$this->plugin->processCckFieldValues($this->migration, 'body', $field_info);
|
||||
|
||||
$process = $this->migration->getProcess();
|
||||
$this->assertSame('sub_process', $process['plugin']);
|
||||
$this->assertSame('body', $process['source']);
|
||||
$this->assertSame('value', $process['process']['value']);
|
||||
|
||||
// Ensure that filter format IDs will be looked up in the filter format
|
||||
// migrations.
|
||||
$lookup = $process['process']['format'][2];
|
||||
$this->assertSame('migration', $lookup['plugin']);
|
||||
$this->assertContains('d6_filter_format', $lookup['migration']);
|
||||
$this->assertContains('d7_filter_format', $lookup['migration']);
|
||||
$this->assertSame('format', $lookup['source']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessBooleanTextImplicitValues() {
|
||||
$info = [
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo\nbar",
|
||||
],
|
||||
];
|
||||
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
'map' => [
|
||||
'bar' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess()['process']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessBooleanTextExplicitValues() {
|
||||
$info = [
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo|Foo\nbaz|Baz",
|
||||
],
|
||||
];
|
||||
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
'map' => [
|
||||
'baz' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess()['process']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetFieldType().
|
||||
*/
|
||||
public function getFieldTypeProvider() {
|
||||
return [
|
||||
['string_long', 'text_textfield', ['text_processing' => FALSE]],
|
||||
['string', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 128,
|
||||
],
|
||||
],
|
||||
['string_long', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 4096,
|
||||
],
|
||||
],
|
||||
['text_long', 'text_textfield', ['text_processing' => TRUE]],
|
||||
['text', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 128,
|
||||
],
|
||||
],
|
||||
['text_long', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 4096,
|
||||
],
|
||||
],
|
||||
['list_string', 'optionwidgets_buttons'],
|
||||
['list_string', 'optionwidgets_select'],
|
||||
['boolean', 'optionwidgets_onoff'],
|
||||
['text_long', 'text_textarea', ['text_processing' => TRUE]],
|
||||
['string_long', 'text_textarea', ['text_processing' => FALSE]],
|
||||
[NULL, 'undefined'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFieldType
|
||||
* @dataProvider getFieldTypeProvider
|
||||
*/
|
||||
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
|
||||
$row = new Row(['widget_type' => $widget_type], ['widget_type' => []]);
|
||||
$row->setSourceProperty('global_settings', $settings);
|
||||
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
|
||||
}
|
||||
|
||||
}
|
|
@ -140,10 +140,6 @@ trait DeprecationListenerTrait {
|
|||
*/
|
||||
public static function getSkippedDeprecations() {
|
||||
return [
|
||||
'MigrateCckField is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.',
|
||||
'MigrateCckFieldPluginManager is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateFieldPluginManager instead.',
|
||||
'MigrateCckFieldPluginManagerInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateFieldPluginManagerInterface instead.',
|
||||
'The "plugin.manager.migrate.cckfield" service is deprecated. You should use the \'plugin.manager.migrate.field\' service instead. See https://www.drupal.org/node/2751897',
|
||||
'Passing in arguments the legacy way is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Provide the right parameter names in the method, similar to controllers. See https://www.drupal.org/node/2894819',
|
||||
'The "serializer.normalizer.file_entity.hal" normalizer service is deprecated: it is obsolete, it only remains available for backwards compatibility.',
|
||||
'The Symfony\Component\ClassLoader\ApcClassLoader class is deprecated since Symfony 3.3 and will be removed in 4.0. Use `composer install --apcu-autoloader` instead.',
|
||||
|
|
Loading…
Reference in New Issue