class D7FileEntityConfigDeriver in Media Migration 8
Deriver for file entities' configuration entity migrations.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\media_migration\Plugin\migrate\D7FileEntityConfigDeriver implements ContainerDeriverInterface uses StringTranslationTrait, MigrationDeriverTrait
Expanded class hierarchy of D7FileEntityConfigDeriver
5 string references to 'D7FileEntityConfigDeriver'
- d7_file_entity_formatter.yml in migrations/
d7_file_entity_formatter.yml - migrations/d7_file_entity_formatter.yml
- d7_file_entity_source_field.yml in migrations/
d7_file_entity_source_field.yml - migrations/d7_file_entity_source_field.yml
- d7_file_entity_source_field_config.yml in migrations/
d7_file_entity_source_field_config.yml - migrations/d7_file_entity_source_field_config.yml
- d7_file_entity_type.yml in migrations/
d7_file_entity_type.yml - migrations/d7_file_entity_type.yml
- d7_file_entity_widget.yml in migrations/
d7_file_entity_widget.yml - migrations/d7_file_entity_widget.yml
File
- src/
Plugin/ migrate/ D7FileEntityConfigDeriver.php, line 23
Namespace
Drupal\media_migration\Plugin\migrateView source
class D7FileEntityConfigDeriver extends DeriverBase implements ContainerDeriverInterface {
use MigrationDeriverTrait;
use StringTranslationTrait;
/**
* The file entity dealer plugin manager.
*
* @var \Drupal\media_migration\FileEntityDealerManagerInterface
*/
protected $fileEntityDealerManager;
/**
* D7FileEntityConfigDeriver constructor.
*
* @param \Drupal\media_migration\FileEntityDealerManagerInterface $file_entity_dealer_manager
* The file entity dealer plugin manager.
*/
public function __construct(FileEntityDealerManagerInterface $file_entity_dealer_manager) {
$this->fileEntityDealerManager = $file_entity_dealer_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('plugin.manager.file_entity_dealer'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$file_entity_types = static::getSourcePlugin('d7_file_entity_type');
try {
$file_entity_types
->checkRequirements();
} catch (RequirementsException $e) {
return $this->derivatives;
}
assert($file_entity_types instanceof DrupalSqlBase);
try {
foreach ($file_entity_types as $file_entity_type_row) {
assert($file_entity_type_row instanceof Row);
[
'types' => $types,
'schemes' => $schemes,
] = $file_entity_type_row
->getSource();
// Multiple types and schemes may have the same destination media type
// ID.
$type = explode(ConfigSourceBase::MULTIPLE_SEPARATOR, $types)[0];
$scheme = explode(ConfigSourceBase::MULTIPLE_SEPARATOR, $schemes)[0];
$dealer_plugin = $this->fileEntityDealerManager
->createInstanceFromTypeAndScheme($type, $scheme);
// No plugin was found for this file entity type row.
if (!$dealer_plugin instanceof FileEntityDealerPluginInterface) {
throw new \LogicException(sprintf('No FileEntityDealer plugin applies for file entities with type "%s" and with scheme "%s/*"', $type, $scheme));
}
$destination_media_type_id = $dealer_plugin
->getDestinationMediaTypeId();
$source_plugin_id = $base_plugin_definition['source']['plugin'];
$derivative_definition = $base_plugin_definition;
// Create the migration derivative.
$derivative_definition['migration_tags'][] = MediaMigration::MIGRATION_TAG_MAIN;
$derivative_definition['migration_tags'][] = MediaMigration::MIGRATION_TAG_CONFIG;
$derivative_definition['source']['schemes'] = $schemes;
$derivative_definition['source']['types'] = $types;
$derivative_definition['source']['destination_media_type_id'] = $destination_media_type_id;
$derivative_definition['label'] = $this
->t('@label (@type)', [
'@label' => $base_plugin_definition['label'],
'@type' => $dealer_plugin
->getDestinationMediaTypeLabel(),
]);
// Post-process migration dependencies: instead of depending on
// migrations based on their base plugin ID, it is better to use the
// corresponding derivatives where possible.
$derived_migration_ids = [
'd7_file_entity_type',
'd7_file_entity_source_field',
'd7_file_entity_source_field_config',
'd7_file_entity_widget',
'd7_file_entity_formatter',
];
foreach ($derived_migration_ids as $derived_migration_base_id) {
$required_dependencies = !empty($derivative_definition['migration_dependencies']['required']) ? $derivative_definition['migration_dependencies']['required'] : [];
$dependency_key = array_search($derived_migration_base_id, $required_dependencies, TRUE);
if ($dependency_key !== FALSE) {
$derivative_definition['migration_dependencies']['required'][$dependency_key] .= PluginBase::DERIVATIVE_SEPARATOR . $destination_media_type_id;
}
}
switch ($source_plugin_id) {
case 'd7_file_entity_type':
$dealer_plugin
->alterMediaTypeMigrationDefinition($derivative_definition, $file_entity_types
->getDatabase());
break;
case 'd7_file_entity_source_field_storage':
$dealer_plugin
->alterMediaSourceFieldStorageMigrationDefinition($derivative_definition, $file_entity_types
->getDatabase());
break;
case 'd7_file_entity_source_field_instance':
$dealer_plugin
->alterMediaSourceFieldInstanceMigrationDefinition($derivative_definition, $file_entity_types
->getDatabase());
break;
case 'd7_file_entity_field_widget':
$dealer_plugin
->alterMediaSourceFieldWidgetMigrationDefinition($derivative_definition, $file_entity_types
->getDatabase());
break;
case 'd7_file_entity_field_formatter':
$dealer_plugin
->alterMediaFieldFormatterMigrationDefinition($derivative_definition, $file_entity_types
->getDatabase());
break;
}
$this->derivatives[$destination_media_type_id] = $derivative_definition;
}
} 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 $this->derivatives;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
D7FileEntityConfigDeriver:: |
protected | property | The file entity dealer plugin manager. | 1 |
D7FileEntityConfigDeriver:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
1 |
D7FileEntityConfigDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
1 |
D7FileEntityConfigDeriver:: |
public | function | D7FileEntityConfigDeriver constructor. | 1 |
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. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
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. |