You are here

public function FileRemoteImage::transform 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::transform()

Performs the associated process.

Parameters

mixed $value: The value to be transformed.

\Drupal\migrate\MigrateExecutableInterface $migrate_executable: The migration in which this process is being executed.

\Drupal\migrate\Row $row: The row from the source to process. Normally, just transforming the value is adequate but very rarely you might need to change two columns at the same time or something like that.

string $destination_property: The destination property currently worked on. This is only used together with the $row above.

Return value

string|array The newly transformed value.

Overrides FileRemoteUrl::transform

File

src/Plugin/migrate/process/FileRemoteImage.php, line 60

Class

FileRemoteImage
Create an image file entity with a remote url without downloading the file.

Namespace

Drupal\migrate_file\Plugin\migrate\process

Code

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;
}