You are here

function _advagg_form_system_performance_settings_alter in Advanced CSS/JS Aggregation 7

@file Admin page callbacks for the advanced CSS/JS aggregation module.

1 call to _advagg_form_system_performance_settings_alter()
advagg_form_system_performance_settings_alter in ./advagg.module
Implements hook_form_FORM_ID_alter().

File

includes/admin.inc, line 8
Admin page callbacks for the advanced CSS/JS aggregation module.

Code

function _advagg_form_system_performance_settings_alter(&$form, &$form_state) {
  $advagg_enabled = isset($form_state['values']['advagg_enabled']) ? (int) $form_state['values']['advagg_enabled'] : (int) variable_get('advagg_enabled', ADVAGG_ENABLED);

  // Provide wrapper so AJAX can replace it.
  $form['bandwidth_optimization']['#prefix'] = '<div id="bandwidth-optimization">';
  $form['bandwidth_optimization']['#suffix'] = '</div>';
  $form['bandwidth_optimization']['aggregation'] = array(
    '#type' => 'fieldset',
    '#title' => t('CSS/JS Aggregation'),
    '#tree' => FALSE,
  );

  // Create toggle for enabling AdvAgg.
  $form['bandwidth_optimization']['aggregation']['advagg_enabled'] = array(
    '#type' => 'radios',
    '#weight' => -1,
    '#options' => array(
      0 => t('Default'),
      1 => t('Advanced'),
    ),
    '#default_value' => $advagg_enabled,
    '#ajax' => array(
      'callback' => 'advagg_form_system_performance_settings_ajax',
      'wrapper' => 'bandwidth-optimization',
      'method' => 'replace',
    ),
  );

  // Create vertical tabs for settings.
  $form['bandwidth_optimization']['aggregation']['aggregation_tabs'] = array(
    '#type' => 'vertical_tabs',
    '#tree' => FALSE,
  );

  // Create fieldset for core settings.
  $form['bandwidth_optimization']['aggregation']['core'] = array(
    '#access' => !(bool) $advagg_enabled,
    '#type' => 'fieldset',
    '#title' => t('Settings'),
    '#group' => 'aggregation_tabs',
    '#tree' => FALSE,
  );

  // Move core settings into fieldset.
  $form['bandwidth_optimization']['aggregation']['core']['preprocess_css'] = $form['bandwidth_optimization']['preprocess_css'];
  $form['bandwidth_optimization']['aggregation']['core']['preprocess_js'] = $form['bandwidth_optimization']['preprocess_js'];
  unset($form['bandwidth_optimization']['preprocess_css']);
  unset($form['bandwidth_optimization']['preprocess_js']);

  // If AdvAgg is not selected, then do not continue altering the form.
  if (!$advagg_enabled) {
    return;
  }

  // Add AdvAgg settings to form.
  $form['bandwidth_optimization']['aggregation']['advagg'] = array(
    '#type' => 'container',
    '#tree' => FALSE,
  );

  // Allow all modules to implement AdvAgg settings.
  foreach (module_implements('advagg_admin_form') as $module) {
    $function = $module . '_advagg_admin_form';
    $function($form['bandwidth_optimization']['aggregation']['advagg'], $form_state);
  }

  // Ensure fieldsets are assigned to the vertical tabs group and values are
  // not inside a tree.
  foreach (element_children($form['bandwidth_optimization']['aggregation']['advagg']) as $key) {
    if (isset($form['bandwidth_optimization']['aggregation']['advagg'][$key]['#type']) && $form['bandwidth_optimization']['aggregation']['advagg'][$key]['#type'] == 'fieldset') {
      $form['bandwidth_optimization']['aggregation']['advagg'][$key]['#group'] = 'aggregation_tabs';
      $form['bandwidth_optimization']['aggregation']['advagg'][$key]['#tree'] = FALSE;
    }
  }
}