You are here

public function ImageImport::transform in Migrate Files (extended) 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/migrate/process/ImageImport.php \Drupal\migrate_file\Plugin\migrate\process\ImageImport::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 FileImport::transform

File

src/Plugin/migrate/process/ImageImport.php, line 97

Class

ImageImport
Imports an image from an local or external source.

Namespace

Drupal\migrate_file\Plugin\migrate\process

Code

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

  // Ignore this setting.
  $this->configuration['id_only'] = FALSE;

  // Run the parent transform to do all the file handling.
  $value = parent::transform($value, $migrate_executable, $row, $destination_property);
  if ($value && is_array($value)) {

    // Add the image field specific sub fields.
    foreach ([
      'title',
      'alt',
      'width',
      'height',
    ] as $key) {
      if ($property = $this->configuration[$key]) {
        if ($property == '!file') {
          $file = File::load($value['target_id']);
          $value[$key] = $file
            ->getFilename();
        }
        else {
          $value[$key] = $this
            ->getPropertyValue($property, $row);
        }
      }
    }
    return $value;
  }
  else {
    return NULL;
  }
}