You are here

function advagg_get_relative_path in Advanced CSS/JS Aggregation 8.2

Same name and namespace in other branches
  1. 7.2 advagg.module \advagg_get_relative_path()

Given a uri, get the relative_path.

Parameters

string $uri: The uri for the stream wrapper.

Return value

string The relative path of the uri.

See also

https://www.drupal.org/node/837794#comment-9124435

3 calls to advagg_get_relative_path()
advagg_ext_minify_css_minify in advagg_ext_minify/advagg_ext_minify.module
Minify CSS using via command line.
advagg_ext_minify_js_minify in advagg_ext_minify/advagg_ext_minify.module
Minify Javascript using via command line.
Files::createSubfile in src/State/Files.php
Write CSS parts to disk; used when CSS selectors in one file is > 4096.

File

./advagg.module, line 533
Advanced CSS/JS aggregation module.

Code

function advagg_get_relative_path($uri) {
  $wrapper = \Drupal::service("stream_wrapper_manager")
    ->getViaUri($uri);
  if ($wrapper instanceof DrupalLocalStreamWrapper) {
    $relative_path = $wrapper
      ->getDirectoryPath() . '/' . file_uri_target($uri);
  }
  else {
    $relative_path = parse_url(file_create_url($uri), PHP_URL_PATH);
    if (substr($relative_path, 0, strlen($GLOBALS['base_path'])) == $GLOBALS['base_path']) {
      $relative_path = substr($relative_path, strlen($GLOBALS['base_path']));
    }
  }
  return $relative_path;
}