public function TranslateCss::optimize in Advanced CSS/JS Aggregation 8.4
Same name and namespace in other branches
- 8.3 advagg_mod/src/Asset/TranslateCss.php \Drupal\advagg_mod\Asset\TranslateCss::optimize()
Optimize the asset's content.
Parameters
string $content: The content to optimize.
array $asset: A core asset array.
array $data: The cache data.
Return value
string The optimized content.
Overrides SingleAssetOptimizerBase::optimize
File
- advagg_mod/
src/ Asset/ TranslateCss.php, line 33
Class
- TranslateCss
- Applies the t() function to strings in CSS assets.
Namespace
Drupal\advagg_mod\AssetCode
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);
}