1 system.admin.inc system_performance_settings($form, &$form_state)

Form builder; Configure site performance settings.

See also

system_performance_settings_submit().

Related topics

File

core/modules/system/system.admin.inc, line 1697
Admin page callbacks for the System module.

Code

function system_performance_settings($form, &$form_state) {
  backdrop_add_js(backdrop_get_path('module', 'system') . '/js/system.admin.js');
  $config = config('system.core');

  $form['#config'] = 'system.core';
  $form['clear_cache'] = array(
    '#type' => 'fieldset',
    '#title' => t('Clear cache'),
    '#access' => user_access('flush caches'),
  );

  $form['clear_cache']['clear'] = array(
    '#type' => 'submit',
    '#value' => t('Clear all caches'),
    '#submit' => array('system_clear_cache_submit'),
  );

  $form['caching'] = array(
    '#type' => 'fieldset',
    '#title' => t('Caching'),
  );

  $form['caching']['cache'] = array(
    '#type' => 'checkbox',
    '#title' => t('Cache pages for anonymous users'),
    '#default_value' => $config->get('cache'),
    '#weight' => -2,
  );
  $form['caching']['page_cache_background_fetch'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use background fetch for cached pages'),
    '#default_value' => $config->get('page_cache_background_fetch'),
    '#description' => t('Allows serving stale pages while new page cache entries are being generated.'),
    '#states' => array(
      'visible' => array(
        ':input[name="cache"]' => array('checked' => TRUE),
      ),
    ),
  );
  $period = backdrop_map_assoc(array(60, 120, 180, 240, 300, 360, 420, 480, 540, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval');
  $form['caching']['page_cache_maximum_age'] = array(
    '#type' => 'select',
    '#title' => t('Expiration of cached pages'),
    '#default_value' => $config->get('page_cache_maximum_age'),
    '#options' => $period,
    '#description' => t('The maximum time the page cache can use an old version of a page.'),
    '#states' => array(
      'visible' => array(
        ':input[name="cache"]' => array('checked' => TRUE),
      ),
    ),
  );

  $directory = 'public://';
  $is_writable = is_dir($directory) && is_writable($directory);
  $disabled = !$is_writable;

  $form['bandwidth_optimization'] = array(
    '#type' => 'fieldset',
    '#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.'),
  );

  if (!$is_writable) {
    $form['bandwidth_optimization']['file_system_message'] = array(
      '#type' => 'container',
      '#attributes' => array('class' => array('messages', 'warning')),
    );
    $form['bandwidth_optimization']['file_system_message']['warning'] = array(
      '#markup' => t('Aggregation of Javascript and CSS files is disabled. You need to set up the <a href="!file-system">public files directory</a> to make these optimizations available.', array('!file-system' => url('admin/config/media/file-system'))),
    );
  }

  $form['bandwidth_optimization']['page_compression'] = array(
    '#type' => 'checkbox',
    '#title' => t('Compress cached pages.'),
    '#default_value' => $config->get('page_compression'),
    '#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('preprocess_css'),
    '#disabled' => $disabled,
  );
  $form['bandwidth_optimization']['preprocess_js'] = array(
    '#type' => 'checkbox',
    '#title' => t('Aggregate JavaScript files.'),
    '#default_value' => $config->get('preprocess_js'),
    '#disabled' => $disabled,
  );

  $form['#submit'][] = 'backdrop_clear_css_cache';
  $form['#submit'][] = 'backdrop_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';

  return system_settings_form($form);
}