You are here

function advagg_mod_advagg_css_contents_alter in Advanced CSS/JS Aggregation 8.2

Implements hook_advagg_css_contents_alter().

Used to run strings inside of quotes of the content attribute through the t function.

See also

\Drupal\Core\Asset\CssOptimizer::processCss

File

advagg_mod/advagg_mod.advagg.inc, line 16
Advanced CSS/JS aggregation modifier module.

Code

function advagg_mod_advagg_css_contents_alter(&$data, $css_asset) {
  $config = \Drupal::config('advagg_mod.settings');
  if (!$config
    ->get('css_translate')) {
    return;
  }

  // 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.
  $css_content_pattern = "/content:.*?({$double_quot}|{$single_quot}|(?:\\;|\\})).*?(?:\\;|\\})/";

  // Run strings inside of quotes of the content attribute through the t
  // function.
  $data = preg_replace_callback($css_content_pattern, 'advagg_mod_advagg_css_content_t_replace_callback', $data);
}