Same name in other branches
  1. 5.0.x src/Asset/CssOptimizer.php \Drupal\advagg\Asset\CssOptimizer::optimizeFile()
  2. 6.0.x src/Asset/CssOptimizer.php \Drupal\advagg\Asset\CssOptimizer::optimizeFile()
  3. 8.x-3.x src/Asset/CssOptimizer.php \Drupal\advagg\Asset\CssOptimizer::optimizeFile()

Overrides AssetOptimizer::optimizeFile

File

src/Asset/CssOptimizer.php, line 84

Class

CssOptimizer
The CSS Optimizer.

Namespace

Drupal\advagg\Asset

Code

protected function optimizeFile(array &$asset, array $data) {
    $contents = $this->updateUrls($data['contents'], $asset['data']);
    if ($this->config
        ->get('css.combine_media') && $asset['media'] !== 'all') {
        $contents = "@media {$asset['media']}{{$contents}}";
        $asset['media'] = 'all';
    }
    $asset_event = new AssetOptimizationEvent($contents, $asset, $data);
    $this->eventDispatcher
        ->dispatch(AssetOptimizationEvent::CSS, $asset_event);
    $contents = $asset_event->getContent();
    $asset = $asset_event->getAsset();
    // If file contents are unaltered return FALSE.
    if ($contents === $data['contents'] && !$this->gZip) {
        return FALSE;
    }
    return $this->writeFile($contents, $data['cid']);
}