function system_performance_settings

Form builder; Configure site performance settings.

See also

system_performance_settings_submit().

Related topics

1 string reference to 'system_performance_settings'
system_menu in drupal/core/modules/system/system.module
Implements hook_menu().

File

drupal/core/modules/system/system.admin.inc, line 1602
Admin page callbacks for the system module.

Code

function system_performance_settings($form, &$form_state) {
  drupal_add_library('system', 'drupal.system');
  $config = config('system.performance');
  $form['clear_cache'] = array(
    '#type' => 'details',
    '#title' => t('Clear cache'),
  );
  $form['clear_cache']['clear'] = array(
    '#type' => 'submit',
    '#value' => t('Clear all caches'),
    '#submit' => array(
      'system_clear_cache_submit',
    ),
  );
  $form['caching'] = array(
    '#type' => 'details',
    '#title' => t('Caching'),
  );
  $form['caching']['cache'] = array(
    '#type' => 'checkbox',
    '#title' => t('Cache pages for anonymous users'),
    '#default_value' => $config
      ->get('cache.page.enabled'),
    '#weight' => -2,
  );
  $period = drupal_map_assoc(array(
    0,
    60,
    180,
    300,
    600,
    900,
    1800,
    2700,
    3600,
    10800,
    21600,
    32400,
    43200,
    86400,
  ), 'format_interval');
  $period[0] = '<' . t('none') . '>';
  $form['caching']['page_cache_maximum_age'] = array(
    '#type' => 'select',
    '#title' => t('Expiration of cached pages'),
    '#default_value' => $config
      ->get('cache.page.max_age'),
    '#options' => $period,
    '#description' => t('The maximum time an external cache can use an old version of a page.'),
  );
  $directory = 'public://';
  $is_writable = is_dir($directory) && is_writable($directory);
  $disabled = !$is_writable;
  $disabled_message = '';
  if (!$is_writable) {
    $disabled_message = ' ' . t('<strong class="error">Set up the <a href="!file-system">public files directory</a> to make these optimizations available.</strong>', array(
      '!file-system' => url('admin/config/media/file-system'),
    ));
  }
  $form['bandwidth_optimization'] = array(
    '#type' => 'details',
    '#title' => t('Bandwidth optimization'),
    '#description' => t('External resources can be optimized automatically, which can reduce both the size and number of requests made to your website.') . $disabled_message,
  );
  $js_hide = $config
    ->get('cache.page.enabled') ? '' : ' class="js-hide"';
  $form['bandwidth_optimization']['page_compression'] = array(
    '#type' => 'checkbox',
    '#title' => t('Compress cached pages.'),
    '#default_value' => $config
      ->get('response.gzip'),
    '#states' => array(
      'visible' => array(
        'input[name="cache"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['bandwidth_optimization']['preprocess_css'] = array(
    '#type' => 'checkbox',
    '#title' => t('Aggregate and compress CSS files.'),
    '#default_value' => $config
      ->get('css.preprocess'),
    '#disabled' => $disabled,
  );
  $form['bandwidth_optimization']['preprocess_js'] = array(
    '#type' => 'checkbox',
    '#title' => t('Aggregate JavaScript files.'),
    '#default_value' => $config
      ->get('js.preprocess'),
    '#disabled' => $disabled,
  );
  $form['#submit'][] = 'drupal_clear_css_cache';
  $form['#submit'][] = 'drupal_clear_js_cache';

  // This form allows page compression settings to be changed, which can
  // invalidate the page cache, so it needs to be cleared on form submit.
  $form['#submit'][] = 'system_clear_page_cache_submit';
  $form['#submit'][] = 'system_performance_settings_submit';
  return system_config_form($form, $form_state);
}