You are here

public function FileUri::transform in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/file/src/Plugin/migrate/process/d6/FileUri.php \Drupal\file\Plugin\migrate\process\d6\FileUri::transform()
  2. 10 core/modules/file/src/Plugin/migrate/process/d6/FileUri.php \Drupal\file\Plugin\migrate\process\d6\FileUri::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/FileUri.php, line 21

Class

FileUri
Process the file url into a D8 compatible URL.

Namespace

Drupal\file\Plugin\migrate\process\d6

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 ($row
    ->isStub()) {
    return NULL;
  }
  list($filepath, $file_directory_path, $temp_directory_path, $is_public) = $value;

  // Specific handling using $temp_directory_path for temporary files.
  if (substr($filepath, 0, strlen($temp_directory_path)) === $temp_directory_path) {
    $uri = preg_replace('/^' . preg_quote($temp_directory_path, '/') . '/', '', $filepath);
    return 'temporary://' . ltrim($uri, '/');
  }

  // Strip the files path from the uri instead of using basename
  // so any additional folders in the path are preserved.
  $uri = preg_replace('/^' . preg_quote($file_directory_path, '/') . '/', '', $filepath);
  return ($is_public ? 'public' : 'private') . '://' . ltrim($uri, '/');
}