You are here

function hook_advagg_css_groups_alter in Advanced CSS/JS Aggregation 7.2

Allow other modules to modify $css_groups right before it is processed.

Parameters

array $css_groups: An associative array. key - group.

bool $preprocess_css: TRUE if preprocessing is enabled.

See also

_advagg_aggregate_css()

advagg_css_cdn_advagg_css_groups_alter()

Related topics

1 function implements hook_advagg_css_groups_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

advagg_css_cdn_advagg_css_groups_alter in advagg_css_cdn/advagg_css_cdn.module
Implements hook_advagg_css_groups_alter().
1 invocation of hook_advagg_css_groups_alter()
_advagg_aggregate_css in ./advagg.module
Default callback to aggregate CSS files and inline content.

File

./advagg.api.php, line 309
Hooks provided by the AdvAgg module.

Code

function hook_advagg_css_groups_alter(array &$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);
}