You are here

class FileRemoteImage in Migrate Files (extended) 8

Same name and namespace in other branches
  1. 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

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\process
View 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

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FileRemoteImage::transform public function Performs the associated process. Overrides FileRemoteUrl::transform
FileRemoteImage::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides FileRemoteUrl::__construct
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
ProcessPluginBase::multiple public function Indicates whether the returned value requires multiple handling. Overrides MigrateProcessInterface::multiple 3
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.