CssOptimizer::loadNestedFile

protected CssOptimizer::loadNestedFile($matches)

Loads stylesheets recursively and returns contents with corrected paths.

This function is used for recursive loading of stylesheets and returns the stylesheet content with all url() paths corrected.

Parameters

array $matches: An array of matches by a preg_replace_callback() call that scans for @import-ed CSS files, except for external CSS files.

Return value

The contents of the CSS file at $matches[1], with corrected paths.

See also

\Drupal\Core\Asset\AssetOptimizerInterface::loadFile()

File

core/lib/Drupal/Core/Asset/CssOptimizer.php, line 156

Class

CssOptimizer
Optimizes a CSS asset.

Namespace

Drupal\Core\Asset

Code

protected function loadNestedFile($matches) {
  $filename = $matches[1];
  // Load the imported stylesheet and replace @import commands in there as
  // well.
  $file = $this->loadFile($filename, NULL, FALSE);

  // Determine the file's directory.
  $directory = dirname($filename);
  // If the file is in the current directory, make sure '.' doesn't appear in
  // the url() path.
  $directory = $directory == '.' ? '' : $directory . '/';

  // Alter all internal url() paths. Leave external paths alone. We don't need
  // to normalize absolute paths here because that will be done later.
  return preg_replace('/url\(\s*([\'"]?)(?![a-z]+:|\/+)([^\'")]+)([\'"]?)\s*\)/i', 'url(\1' . $directory . '\2\3)', $file);
}
doc_Drupal
2016-10-29 08:59:18
Comments
Leave a Comment

Please login to continue.