Commit 9dc2137d authored by heddn's avatar heddn Committed by bojanz

Issue #2912087 by heddn, quietone: Field plugin migration from D7/addressfield

parent 1dac9972
......@@ -2,8 +2,11 @@
namespace Drupal\address\Plugin\migrate\cckfield;
@trigger_error('AddressField is deprecated in Address 1.3 and will be be removed before Address 2.x. Use \Drupal\address\Plugin\migrate\field\AddressField instead.', E_USER_DEPRECATED);
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
use Drupal\address\Plugin\migrate\field\AddressField as BaseAddressField;
use Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface;
/**
* @MigrateCckField(
......@@ -13,36 +16,17 @@ use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
* "addressfield" = "address"
* }
* )
*
* @deprecated in 1.3, to be removed before 2.x. Use
* \Drupal\address\Plugin\migrate\field\AddressField instead.
*/
class AddressField extends CckFieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return [
'addressfield_default' => 'address_default',
];
}
/**
* {@inheritdoc}
*/
public function getFieldWidgetMap() {
return [
'addressfield_standard' => 'address_default',
];
}
class AddressField extends BaseAddressField implements MigrateCckFieldInterface {
/**
* {@inheritdoc}
*/
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = [
'plugin' => 'addressfield',
'source' => $field_name,
];
$migration->mergeProcessOfProperty($field_name, $process);
return $this->processFieldValues($migration, $field_name, $data);
}
}
<?php
namespace Drupal\address\Plugin\migrate\field;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
/**
* @MigrateField(
* id = "addressfield",
* core = {7},
* type_map = {
* "addressfield" = "address"
* }
* )
*/
class AddressField extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return [
'addressfield_default' => 'address_default',
];
}
/**
* {@inheritdoc}
*/
public function getFieldWidgetMap() {
return [
'addressfield_standard' => 'address_default',
];
}
/**
* {@inheritdoc}
*/
public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = [
'plugin' => 'addressfield',
'source' => $field_name,
];
$migration->mergeProcessOfProperty($field_name, $process);
}
}
<?php
namespace Drupal\Tests\address\Kernel;
use Drupal\address\Plugin\migrate\field\AddressField;
use Drupal\address\Plugin\migrate\cckfield\AddressField as CckAddressField;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate\Plugin\MigrationInterface;
/**
* Tests the address field field plugin.
*
* @group address
*/
class AddressFieldTest extends KernelTestBase {
/**
* @var array
*/
public static $modules = [
'address',
'migrate',
'migrate_drupal',
];
/**
* Tests discovery of the field plugin.
*/
public function testPlugin() {
$migration = $this->prophesize(MigrationInterface::class)->reveal();
$field_plugin = $this->container
->get('plugin.manager.migrate.field')
->createInstance('addressfield', [], $migration);
$this->assertInstanceOf(AddressField::class, $field_plugin);
}
/**
* Tests discovery of the cck field plugin.
*/
public function testLegacyPlugin() {
$migration = $this->prophesize(MigrationInterface::class)->reveal();
$field_plugin = $this->container
->get('plugin.manager.migrate.cckfield')
->createInstance('addressfield', [], $migration);
$this->assertInstanceOf(CckAddressField::class, $field_plugin);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment