Same name in other branches
- 6.0.x src/Asset/CssOptimizer.php \Drupal\advagg\Asset\CssOptimizer::updateUrls()
- 8.x-3.x src/Asset/CssOptimizer.php \Drupal\advagg\Asset\CssOptimizer::updateUrls()
- 8.x-4.x src/Asset/CssOptimizer.php \Drupal\advagg\Asset\CssOptimizer::updateUrls()
Update any internal urls.
Parameters
string $contents: The file contents.
string $path: The file path.
Return value
string The updated contents.
1 call to CssOptimizer::updateUrls()
- CssOptimizer::optimizeFile in src/
Asset/ CssOptimizer.php - Perform any in-place optimization & pass to event for further optimization.
File
-
src/
Asset/ CssOptimizer.php, line 113
Class
- CssOptimizer
- The CSS Optimizer.
Namespace
Drupal\advagg\AssetCode
public function updateUrls($contents, $path) {
// Determine the file's directory including the Drupal base path.
$directory = base_path() . dirname($path) . '/';
// Alter all internal url() paths. Leave external paths alone. We don't need
// to normalize absolute paths here because that will be done later. Also
// ignore SVG paths (# or %23). Expected form: url("/images/file.jpg") which
// gets converted to url("${directory}/images/file.jpg").
return preg_replace('/url\\(\\s*([\'"]?)(?![a-z]+:|\\/+|\\#|\\%23+)([^\'")]+)([\'"]?)\\s*\\)/i', 'url(\\1' . $directory . '\\2\\3)', $contents);
}