function CssOptimizer::processFile

Same name in other branches
  1. 9 core/lib/Drupal/Core/Asset/CssOptimizer.php \Drupal\Core\Asset\CssOptimizer::processFile()
  2. 10 core/lib/Drupal/Core/Asset/CssOptimizer.php \Drupal\Core\Asset\CssOptimizer::processFile()
  3. 11.x core/lib/Drupal/Core/Asset/CssOptimizer.php \Drupal\Core\Asset\CssOptimizer::processFile()

Build aggregate CSS file.

1 call to CssOptimizer::processFile()
CssOptimizer::optimize in core/lib/Drupal/Core/Asset/CssOptimizer.php
Optimizes an asset.

File

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

Class

CssOptimizer
Optimizes a CSS asset.

Namespace

Drupal\Core\Asset

Code

protected function processFile($css_asset) {
    $contents = $this->loadFile($css_asset['data'], TRUE);
    $contents = $this->clean($contents);
    // Get the parent directory of this file, relative to the Drupal root.
    $css_base_path = substr($css_asset['data'], 0, strrpos($css_asset['data'], '/'));
    // Store base path.
    $this->rewriteFileURIBasePath = $css_base_path . '/';
    // Anchor all paths in the CSS with its base URL, ignoring external and absolute paths.
    return preg_replace_callback('/url\\(\\s*[\'"]?(?![a-z]+:|\\/+)([^\'")]+)[\'"]?\\s*\\)/i', [
        $this,
        'rewriteFileURI',
    ], $contents);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.