Same name in other branches
- 5.0.x advagg_css_minify/src/Asset/CssMinifier.php \Drupal\advagg_css_minify\Asset\CssMinifier::optimize()
- 6.0.x advagg_css_minify/src/Asset/CssMinifier.php \Drupal\advagg_css_minify\Asset\CssMinifier::optimize()
- 8.x-4.x advagg_css_minify/src/Asset/CssMinifier.php \Drupal\advagg_css_minify\Asset\CssMinifier::optimize()
Overrides SingleAssetOptimizerBase::optimize
1 call to CssMinifier::optimize()
- CssMinifier::loadFile in advagg_css_minify/
src/ Asset/ CssMinifier.php - Loads the stylesheet and resolves all @import commands.
File
-
advagg_css_minify/
src/ Asset/ CssMinifier.php, line 31
Class
- CssMinifier
- Optimizes a JavaScript asset.
Namespace
Drupal\advagg_css_minify\AssetCode
public function optimize($contents, array $asset, array $data) {
// Do nothing if css file minification is disabled.
if (!($minifier = $this->config
->get('minifier'))) {
return $contents;
}
// Do not re-minify if the file is already minified.
if ($this->isMinified($contents)) {
return $contents;
}
$contents = $this->clean($contents, $asset);
$contents_original = $contents;
// Do nothing if core minification is selected.
if ($minifier === 1) {
$contents = trim($this->minifyCore($contents));
}
else {
$contents = trim($this->minifyCssMin($contents));
}
// If the contents are not empty, ensure that $data ends with ; or }.
if (trim($contents) !== "" && strpbrk(substr(trim($contents), -1), ';})') === FALSE) {
$contents .= ';';
}
if (!$this->isMinificationSuccess($contents, $contents_original)) {
return $contents_original;
}
return $contents;
}