View source
<?php
namespace Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\MigratePluginManagerInterface;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
class CommerceFieldName extends ProcessPluginBase implements ContainerFactoryPluginInterface {
protected $processPluginManager;
protected $migrationPluginManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationPluginManagerInterface $migration_plugin_manager, MigratePluginManagerInterface $process_plugin_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migrationPluginManager = $migration_plugin_manager;
$this->processPluginManager = $process_plugin_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('plugin.manager.migration'), $container
->get('plugin.manager.migrate.process'));
}
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$field_name = $row
->getSourceProperty('field_name');
$entity_type = $row
->getSourceProperty('entity_type');
$type = $row
->getSourceProperty('type');
if ($entity_type == 'commerce_product' && $type == 'taxonomy_term_reference') {
$instances = $row
->getSourceProperty('instances');
foreach ($instances as $instance) {
$data = unserialize($instance['data']);
if ($data['widget']['type'] == 'options_select') {
$field_name = preg_replace('/^field_/', 'attribute_', $field_name);
$migration = $this->migrationPluginManager
->createStubMigration([]);
$configuration = [
'entity_type' => 'commerce_product_attribute',
'field' => 'field_name',
'length' => 29,
];
$plugin = $this->processPluginManager
->createInstance('make_unique_entity_field', $configuration, $migration);
$field_name = $plugin
->transform($field_name, $migrate_executable, $row, 'tmp');
}
break;
}
}
if ($entity_type == 'commerce_customer_profile' && $type == 'addressfield') {
$field_name = 'address';
}
return $field_name;
}
}