You are here

protected function EntityFile::urlencode in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Plugin/migrate/destination/EntityFile.php \Drupal\file\Plugin\migrate\destination\EntityFile::urlencode()

Urlencode all the components of a remote filename.

Parameters

string $filename: The filename of the file to be urlencoded.

Return value

string The urlencoded filename.

1 call to EntityFile::urlencode()
EntityFile::writeFile in core/modules/file/src/Plugin/migrate/destination/EntityFile.php
Tries to move or copy a file.

File

core/modules/file/src/Plugin/migrate/destination/EntityFile.php, line 259
Contains \Drupal\file\Plugin\migrate\destination\EntityFile.

Class

EntityFile
Every migration that uses this destination must have an optional dependency on the d6_file migration to ensure it runs first.

Namespace

Drupal\file\Plugin\migrate\destination

Code

protected function urlencode($filename) {

  // Only apply to a full URL
  if ($this->configuration['urlencode'] && strpos($filename, '://')) {
    $components = explode('/', $filename);
    foreach ($components as $key => $component) {
      $components[$key] = rawurlencode($component);
    }
    $filename = implode('/', $components);

    // Actually, we don't want certain characters encoded
    $filename = str_replace('%3A', ':', $filename);
    $filename = str_replace('%3F', '?', $filename);
    $filename = str_replace('%26', '&', $filename);
  }
  return $filename;
}