You are here

function printable_file_url_alter in Printer and PDF versions for Drupal 8+ 2.x

Same name and namespace in other branches
  1. 8 printable.module \printable_file_url_alter()

Make file urls absolute if we're generating a PDF.

Parameters

string $uri: URI to be altered.

File

./printable.module, line 272
Provides printer friendly content entities.

Code

function printable_file_url_alter(&$uri) {
  if (printable_preparing_pdf()) {
    $scheme = \Drupal::service('stream_wrapper_manager')
      ->isValidScheme($uri);
    if ($scheme) {
      $path = \Drupal::service('file_system')
        ->realpath($scheme . '://');
      $uri = ($path ? $path . '/' : '') . substr($uri, strlen($scheme) + 3);
    }
    else {
      $base_url = \Drupal::request()
        ->getSchemeAndHttpHost();
      if (substr($uri, 0, strlen($base_url)) == $base_url) {
        $uri = substr($uri, strlen($base_url) + 1);
      }
      $uri = DRUPAL_ROOT . '/' . $uri;
    }
    $uri = 'printable://' . $uri;
  }
}