You are here

public function CckFile::transform in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Plugin/migrate/process/d6/CckFile.php \Drupal\file\Plugin\migrate\process\d6\CckFile::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 ProcessPluginBase::transform

File

core/modules/file/src/Plugin/migrate/process/d6/CckFile.php, line 76
Contains \Drupal\file\Plugin\migrate\process\d6\CckFile.

Class

CckFile
Plugin annotation @MigrateProcessPlugin( id = "d6_cck_file" )

Namespace

Drupal\file\Plugin\migrate\process\d6

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  $options = unserialize($value['data']);

  // Try to look up the ID of the migrated file. If one cannot be found, it
  // means the file referenced by the current field item did not migrate for
  // some reason -- file migration is notoriously brittle -- and we do NOT
  // want to send invalid file references into the field system (it causes
  // fatals), so return an empty item instead.
  try {
    $fid = $this->migrationPlugin
      ->transform($value['fid'], $migrate_executable, $row, $destination_property);
  } catch (MigrateSkipRowException $e) {
    return [];
  }
  if ($fid) {
    return [
      'target_id' => $fid,
      'display' => $value['list'],
      'description' => isset($options['description']) ? $options['description'] : '',
      'alt' => isset($options['alt']) ? $options['alt'] : '',
      'title' => isset($options['title']) ? $options['title'] : '',
    ];
  }
  else {
    return [];
  }
}