class ProductDeriver in Commerce Migrate 3.1.x
Same name and namespace in other branches
- 8.2 modules/commerce/src/Plugin/migrate/ProductDeriver.php \Drupal\commerce_migrate_commerce\Plugin\migrate\ProductDeriver
- 3.0.x modules/commerce/src/Plugin/migrate/ProductDeriver.php \Drupal\commerce_migrate_commerce\Plugin\migrate\ProductDeriver
Deriver for Commerce 1 products.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\commerce_migrate_commerce\Plugin\migrate\ProductDeriver implements ContainerDeriverInterface uses StringTranslationTrait, MigrationDeriverTrait
Expanded class hierarchy of ProductDeriver
1 string reference to 'ProductDeriver'
- commerce1_product.yml in modules/
commerce/ migrations/ commerce1_product.yml - modules/commerce/migrations/commerce1_product.yml
File
- modules/
commerce/ src/ Plugin/ migrate/ ProductDeriver.php, line 17
Namespace
Drupal\commerce_migrate_commerce\Plugin\migrateView source
class ProductDeriver extends DeriverBase implements ContainerDeriverInterface {
use MigrationDeriverTrait;
use StringTranslationTrait;
/**
* The base plugin ID this derivative is for.
*
* @var string
*/
protected $basePluginId;
/**
* Whether or not to include translations.
*
* @var bool
*/
protected $includeTranslations;
/**
* The migration field discovery service.
*
* @var \Drupal\migrate_drupal\FieldDiscoveryInterface
*/
protected $fieldDiscovery;
/**
* D7NodeDeriver constructor.
*
* @param string $base_plugin_id
* The base plugin ID for the plugin ID.
* @param bool $translations
* Whether or not to include translations.
* @param \Drupal\migrate_drupal\FieldDiscoveryInterface $field_discovery
* The migration field discovery service.
*/
public function __construct($base_plugin_id, $translations, FieldDiscoveryInterface $field_discovery) {
$this->basePluginId = $base_plugin_id;
$this->includeTranslations = $translations;
$this->fieldDiscovery = $field_discovery;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
// Translations don't make sense unless we have content_translation.
return new static($base_plugin_id, $container
->get('module_handler')
->moduleExists('content_translation'), $container
->get('migrate_drupal.field_discovery'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$product_types = static::getSourcePlugin('commerce1_product_display_type');
try {
$product_types
->checkRequirements();
} catch (RequirementsException $e) {
// If the d7_product_display_types requirements failed, that means we do
// not have a Drupal source database configured - there is nothing to
// generate.
return $this->derivatives;
}
$fields = [];
try {
$source_plugin = static::getSourcePlugin('d7_field_instance');
$source_plugin
->checkRequirements();
// Read all field instance definitions in the source database.
foreach ($source_plugin as $row) {
if ($row
->getSourceProperty('entity_type') == 'node') {
$fields[$row
->getSourceProperty('bundle')][$row
->getSourceProperty('field_name')] = $row
->getSource();
}
}
} catch (RequirementsException $e) {
// If checkRequirements() failed then the field module did not exist and
// we do not have any fields. Therefore, $fields will be empty and below
// we'll create a migration just for the product properties.
}
try {
foreach ($product_types as $row) {
$product_type = $row
->getSourceProperty('type');
$values = $base_plugin_definition;
$values['label'] = $this
->t('@label (@type)', [
'@label' => $values['label'],
'@type' => $row
->getSourceProperty('name'),
]);
$values['source']['product_type'] = $product_type;
$values['destination']['default_bundle'] = $product_type;
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
$migration = \Drupal::service('plugin.manager.migration')
->createStubMigration($values);
$this->fieldDiscovery
->addBundleFieldProcesses($migration, 'node', $product_type);
$this->derivatives[$product_type] = $migration
->getPluginDefinition();
}
} catch (DatabaseExceptionWrapper $e) {
// Once we begin iterating the source plugin it is possible that the
// source tables will not exist. This can happen when the
// MigrationPluginManager gathers up the migration definitions but we do
// not actually have a Drupal 7 source database.
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
MigrationDeriverTrait:: |
public static | function | Returns a fully initialized instance of a source plugin. | |
ProductDeriver:: |
protected | property | The base plugin ID this derivative is for. | |
ProductDeriver:: |
protected | property | The migration field discovery service. | |
ProductDeriver:: |
protected | property | Whether or not to include translations. | |
ProductDeriver:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
ProductDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
ProductDeriver:: |
public | function | D7NodeDeriver constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |