class FileRemoteImage in Migrate Files (extended) 8
Same name and namespace in other branches
- 2.0.x src/Plugin/migrate/process/FileRemoteImage.php \Drupal\migrate_file\Plugin\migrate\process\FileRemoteImage
Create an image file entity with a remote url without downloading the file.
This is almost the same as file_remote_url except it supports supplying a width and height for the image for image fields. This will prevent the image module from requesting the image file to measure the width and height which can slow down migrations with lots of remote images.
Available configuration keys:
- uid: (optional) The uid to attribute the file entity to. Defaults to 0.
- width: (optional) The width of the image(s)
- height: (optional) The height of the image(s)
Example:
destination:
plugin: entity:node
process:
field_image:
plugin: file_remote_image
source: https://www.drupal.org/files/drupal_logo-blue.png
Plugin annotation
@MigrateProcessPlugin(
id = "file_remote_url"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\migrate\ProcessPluginBase implements MigrateProcessInterface
- class \Drupal\migrate_file\Plugin\migrate\process\FileRemoteUrl
- class \Drupal\migrate_file\Plugin\migrate\process\FileRemoteImage
- class \Drupal\migrate_file\Plugin\migrate\process\FileRemoteUrl
- class \Drupal\migrate\ProcessPluginBase implements MigrateProcessInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of FileRemoteImage
See also
https://www.drupal.org/project/remote_stream_wrapper
\Drupal\migrate\Plugin\MigrateProcessInterface
File
- src/
Plugin/ migrate/ process/ FileRemoteImage.php, line 43
Namespace
Drupal\migrate_file\Plugin\migrate\processView source
class FileRemoteImage extends FileRemoteUrl {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
$configuration += [
'uid' => 0,
'width' => NULL,
'height' => NULL,
];
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// If we're stubbing a file entity, return a URI of NULL so it will get
// stubbed by the general process.
if (!$value) {
return NULL;
}
// Process the file
$file = parent::transform($value, $migrate_executable, $row, $destination_property);
if ($this->configuration['width'] && $this->configuration['height']) {
return [
'target_id' => $file
->id(),
'width' => $this->configuration['width'],
'height' => $this->configuration['height'],
];
}
return $file;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FileRemoteImage:: |
public | function |
Performs the associated process. Overrides FileRemoteUrl:: |
|
FileRemoteImage:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides FileRemoteUrl:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
ProcessPluginBase:: |
public | function |
Indicates whether the returned value requires multiple handling. Overrides MigrateProcessInterface:: |
3 |
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. |