Same name in other branches
  1. 5.0.x advagg_mod/src/Asset/TranslateCss.php \Drupal\advagg_mod\Asset\TranslateCss::optimize()
  2. 6.0.x advagg_mod/src/Asset/TranslateCss.php \Drupal\advagg_mod\Asset\TranslateCss::optimize()
  3. 8.x-4.x advagg_mod/src/Asset/TranslateCss.php \Drupal\advagg_mod\Asset\TranslateCss::optimize()

Overrides SingleAssetOptimizerBase::optimize

Fichier

advagg_mod/src/Asset/TranslateCss.php, line 33

Classe

TranslateCss
Applies the t() function to strings in CSS assets.

Namespace

Drupal\advagg_mod\Asset

Code

public function optimize($contents, array $asset, array $data) {
    // Code taken from \Drupal\Core\Asset\CssOptimizer::processCss().
    // Regexp to match double quoted strings.
    $double_quot = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"';
    // Regexp to match single quoted strings.
    $single_quot = "'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'";
    // Extract all content inside of quotes.
    $pattern = "/content:.*?({$double_quot}|{$single_quot}|(?:\\;|\\})).*?(?:\\;|\\})/";
    // Run strings inside of quotes of the content attribute through the t
    // function.
    return preg_replace_callback($pattern, [
        $this,
        'translateCallback',
    ], $contents);
}