You are here

public function DemoImage::transform in Panopoly 8.2

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 ProcessPluginBase::transform

File

modules/panopoly/panopoly_core/src/Plugin/migrate/process/DemoImage.php, line 254

Class

DemoImage
Process plugin for creating demo images from files in the module.

Namespace

Drupal\panopoly_core\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {

  // The only required property is the filename property.
  if (empty($this->configuration['filename_property'])) {
    return [];
  }
  $filename = $row
    ->getSourceProperty($this->configuration['filename_property']);
  $destination_path = $this
    ->getDestinationPath() . '/' . $filename;
  $source_path = $this
    ->getSourcePath() . '/' . $filename;
  if (!$this
    ->checkFile($source_path)) {
    throw new MigrateException('Cannot find source image: ' . $source_path);
  }
  $file = $this
    ->findOrCreateFile($source_path, $destination_path);
  $image = $this->imageFactory
    ->get($destination_path);
  return [
    'target_id' => $file
      ->id(),
    'display' => 1,
    'description' => $this
      ->getOptionalProperty('description_property', $row) ?: '',
    'alt' => $this
      ->getOptionalProperty('alt_property', $row) ?: '',
    'title' => $this
      ->getOptionalProperty('title_property', $row) ?: '',
    'width' => $image
      ->getWidth(),
    'height' => $image
      ->getHeight(),
  ];
}