Implements hook_advagg_css_groups_alter().

Related topics

File

advagg_css_cdn/advagg_css_cdn.module, line 76

Code

function advagg_css_cdn_advagg_css_groups_alter(&$css_groups, $preprocess_css) {
    // Work around a bug with seven_css_alter.
    // http://drupal.org/node/1937860
    $theme_keys[] = $GLOBALS['theme'];
    if (!empty($GLOBALS['base_theme_info'])) {
        foreach ($GLOBALS['base_theme_info'] as $base) {
            $theme_keys[] = $base->name;
        }
    }
    $match = FALSE;
    foreach ($theme_keys as $name) {
        if ($name === 'seven') {
            $match = TRUE;
        }
    }
    if (empty($match)) {
        return;
    }
    $target = FALSE;
    $last_group = FALSE;
    $last_key = FALSE;
    $kill_key = FALSE;
    $replaced = FALSE;
    foreach ($css_groups as $key => $group) {
        if (empty($target)) {
            if ($group['type'] === 'external' && $group['preprocess'] && $preprocess_css) {
                foreach ($group['items'] as $k => $value) {
                    if ($value['data'] === 'themes/seven/jquery.ui.theme.css') {
                        // Type should be file and not external (core bug).
                        $value['type'] = 'file';
                        $target = $value;
                        unset($css_groups[$key]['items'][$k]);
                        if (empty($css_groups[$key]['items'])) {
                            unset($css_groups[$key]);
                            $kill_key = $key;
                        }
                    }
                }
            }
        }
        else {
            $diff = array_merge(array_diff_assoc($group['browsers'], $target['browsers']), array_diff_assoc($target['browsers'], $group['browsers']));
            if ($group['type'] != $target['type'] || $group['group'] != $target['group'] || $group['every_page'] != $target['every_page'] || $group['media'] != $target['media'] || $group['media'] != $target['media'] || $group['preprocess'] != $target['preprocess'] || !empty($diff)) {
                if (!empty($last_group)) {
                    $diff = array_merge(array_diff_assoc($last_group['browsers'], $target['browsers']), array_diff_assoc($target['browsers'], $last_group['browsers']));
                    if ($last_group['type'] != $target['type'] || $last_group['group'] != $target['group'] || $last_group['every_page'] != $target['every_page'] || $last_group['media'] != $target['media'] || $last_group['media'] != $target['media'] || $last_group['preprocess'] != $target['preprocess'] || !empty($diff)) {
                        // Insert New.
                        $css_groups[$kill_key] = array(
                            'group' => $target['group'],
                            'type' => $target['type'],
                            'every_page' => $target['every_page'],
                            'media' => $target['media'],
                            'preprocess' => $target['preprocess'],
                            'browsers' => $target['browsers'],
                            'items' => array(
                                $target,
                            ),
                        );
                        $replaced = TRUE;
                    }
                    else {
                        // Insert above.
                        $css_groups[$last_key]['items'][] = $target;
                        $replaced = TRUE;
                    }
                }
            }
            else {
                // Insert below.
                array_unshift($css_groups[$key]['items'], $target);
                $replaced = TRUE;
            }
        }
        $last_group = $group;
        $last_key = $key;
        if ($replaced) {
            break;
        }
    }
    ksort($css_groups);
}