Same name in other branches
  1. 5.0.x advagg.module \advagg_css_alter()
  2. 6.0.x advagg.module \advagg_css_alter()
  3. 8.x-2.x advagg.module \advagg_css_alter()
  4. 8.x-3.x advagg.module \advagg_css_alter()
  5. 8.x-4.x advagg.module \advagg_css_alter()

Implements hook_css_alter().

Fichier

advagg_font/advagg_font.module, line 136

Code

function advagg_css_alter(&$css) {
    // Skip if advagg is disabled.
    if (!advagg_enabled()) {
        return;
    }
    // Skip if fontface is disabled.
    if (empty(variable_get('advagg_font_fontfaceobserver', ADVAGG_FONT_FONTFACEOBSERVER))) {
        return;
    }
    // Skip if fonts added to critical css is disabled.
    if (empty(variable_get('advagg_font_add_to_critical_css', ADVAGG_FONT_ADD_TO_CRITICAL_CSS))) {
        return;
    }
    $critical_css_key = NULL;
    foreach ($css as $key => $values) {
        if (!empty($values['critical-css']) && $values['type'] === 'inline') {
            $critical_css_key = $key;
        }
    }
    // Skip if no critical css.
    if (is_null($critical_css_key)) {
        return;
    }
    module_load_include('inc', 'advagg', 'advagg');
    $css_to_add = '';
    foreach ($css as $key => $values) {
        if ($values['type'] === 'file') {
            $info = advagg_get_info_on_file($key);
            if (!empty($info['advagg_font'])) {
                // Get the file contents.
                $file_contents = (string) @advagg_file_get_contents($info['data']);
                if (empty($file_contents)) {
                    continue;
                }
                list($replacements) = advagg_font_get_replacements_array($file_contents);
                foreach ($replacements as $replace) {
                    $css_to_add .= $replace[2];
                }
            }
        }
    }
    if (!empty($css_to_add)) {
        $css[$critical_css_key]['data'] .= "\n{$css_to_add}";
    }
}