abstract class FileEntityConfigSourceBase in Media Migration 8
Base class for config migrate source plugins of file entity migrations.
Hierarchy
- class \Drupal\media_migration\Plugin\migrate\source\d7\ConfigSourceBase extends \Drupal\media_migration\Plugin\migrate\source\d7\DrupalSqlBaseWithCountCompatibility uses MediaMigrationDatabaseTrait
- class \Drupal\media_migration\Plugin\migrate\source\d7\FileEntityConfigSourceBase
Expanded class hierarchy of FileEntityConfigSourceBase
File
- src/
Plugin/ migrate/ source/ d7/ FileEntityConfigSourceBase.php, line 14
Namespace
Drupal\media_migration\Plugin\migrate\source\d7View source
abstract class FileEntityConfigSourceBase extends ConfigSourceBase {
/**
* The file entity dealer plugin manager.
*
* @var \Drupal\media_migration\FileEntityDealerManagerInterface
*/
protected $fileEntityDealerManager;
/**
* Constructs a plugin instance.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The current migration.
* @param \Drupal\Core\State\StateInterface $state
* The state service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\media_migration\FileEntityDealerManagerInterface $file_entity_dealer_manager
* The file entity dealer plugin manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityTypeManagerInterface $entity_type_manager, FileEntityDealerManagerInterface $file_entity_dealer_manager) {
$configuration += [
'types' => NULL,
'schemes' => NULL,
];
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_type_manager);
$this->fileEntityDealerManager = $file_entity_dealer_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new static($configuration, $plugin_id, $plugin_definition, $migration, $container
->get('state'), $container
->get('entity_type.manager'), $container
->get('plugin.manager.file_entity_dealer'));
}
/**
* {@inheritdoc}
*/
public function query() {
[
'types' => $types,
'schemes' => $schemes,
] = $this->configuration;
$query = $this
->getFileEntityBaseQuery();
if ($types) {
$query
->condition('fm.type', explode(static::MULTIPLE_SEPARATOR, $types), 'IN');
}
if ($schemes) {
$query
->where("{$this->getSchemeExpression()} IN (:schemes[])", [
':schemes[]' => explode(static::MULTIPLE_SEPARATOR, $schemes),
]);
}
return $query;
}
/**
* {@inheritdoc}
*/
protected function prepareQuery() {
parent::prepareQuery();
$this->query
->addTag('migrate__media_migration');
$this->query
->addTag('migrate__media_migration__file_entity');
$this->query
->addTag('migrate__media_migration__media_configuration');
$this->query
->addTag("migrate__media_migration__source__{$this->pluginId}");
return $this->query;
}
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
$results = $this
->prepareQuery()
->execute()
->fetchAll();
$rows = [];
foreach ($results as $result) {
[
'type' => $type,
'scheme' => $scheme,
] = $result;
if (!($dealer_plugin = $this->fileEntityDealerManager
->createInstanceFromTypeAndScheme($type, $scheme))) {
continue;
}
$destination_media_type_id = $dealer_plugin
->getDestinationMediaTypeId();
$source_values = $rows[$destination_media_type_id] ?? $result + [
'types' => $type,
'schemes' => $scheme,
];
$source_values['types'] = implode(static::MULTIPLE_SEPARATOR, array_unique(array_merge(explode(static::MULTIPLE_SEPARATOR, $source_values['types']), [
$type,
])));
$source_values['schemes'] = implode(static::MULTIPLE_SEPARATOR, array_unique(array_merge(explode(static::MULTIPLE_SEPARATOR, $source_values['schemes']), [
$scheme,
])));
$source_values['bundle'] = $destination_media_type_id;
$source_values['bundle_label'] = $dealer_plugin
->getDestinationMediaTypeLabel();
$source_values['source_plugin_id'] = $dealer_plugin
->getDestinationMediaSourcePluginId();
$source_values['source_field_name'] = $dealer_plugin
->getDestinationMediaSourceFieldName();
$source_values['source_field_label'] = $dealer_plugin
->getDestinationMediaTypeSourceFieldLabel();
unset($source_values['type']);
unset($source_values['scheme']);
$rows[$destination_media_type_id] = $source_values;
}
return new \ArrayIterator($rows);
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'types' => $this
->t('File Entity type machine name'),
'schemes' => $this
->t('The uri scheme of the file entities'),
'bundle' => 'bundle',
'bundle_label' => 'bundle_label',
'source_plugin_id' => $this
->t('The source plugin id of the destination media type'),
'source_field_name' => $this
->t('The source field name of the destination media type'),
'source_field_label' => 'source_field_label',
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['types']['type'] = 'string';
$ids['schemes']['type'] = 'string';
return $ids;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigSourceBase:: |
constant | |||
FileEntityConfigSourceBase:: |
protected | property | The file entity dealer plugin manager. | |
FileEntityConfigSourceBase:: |
public static | function | ||
FileEntityConfigSourceBase:: |
public | function | 3 | |
FileEntityConfigSourceBase:: |
public | function | 2 | |
FileEntityConfigSourceBase:: |
protected | function | 2 | |
FileEntityConfigSourceBase:: |
protected | function | ||
FileEntityConfigSourceBase:: |
public | function | 1 | |
FileEntityConfigSourceBase:: |
public | function | Constructs a plugin instance. | |
MediaMigrationDatabaseTrait:: |
protected | function | Returns the file extension expression for the current DB. | |
MediaMigrationDatabaseTrait:: |
protected | function | Returns a base query for file entity types. | |
MediaMigrationDatabaseTrait:: |
protected | function | Returns a base query for plain files. | |
MediaMigrationDatabaseTrait:: |
protected | function | Returns the main MIME type's expression for the current DB. | |
MediaMigrationDatabaseTrait:: |
protected | function | Returns the expression for the DB for getting the URI scheme. | |
MediaMigrationDatabaseTrait:: |
protected | function | Returns the subquery for the user picture-only file IDs. | |
MediaMigrationDatabaseTrait:: |
protected | function | Subquery for FIDs used only in webform submissions and/or by user entities. |