public function PerformanceForm::buildForm

Implements \Drupal\Core\Form\FormInterface::buildForm().

Overrides SystemConfigFormBase::buildForm

File

drupal/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php, line 64
Contains \Drupal\system\Form\PerformanceForm.

Class

PerformanceForm
Configure performance settings for this site.

Namespace

Drupal\system\Form

Code

public function buildForm(array $form, array &$form_state) {
  $form['#attached']['library'][] = array(
    'system',
    'drupal.system',
  );
  $config = $this->configFactory
    ->get('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(
      array(
        $this,
        'submitCacheClear',
      ),
    ),
  );
  $form['caching'] = array(
    '#type' => 'details',
    '#title' => t('Caching'),
  );
  $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('Page cache maximum age'),
    '#default_value' => $config
      ->get('cache.page.max_age'),
    '#options' => $period,
    '#description' => t('The maximum time a page can be cached. This is used as the value for max-age in Cache-Control headers.'),
  );
  $form['caching']['cache'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use internal page cache'),
    '#description' => t("If a reverse proxy cache isn't available, use Drupal's internal cache system to store cached pages."),
    '#default_value' => $config
      ->get('cache.page.use_internal'),
  );
  $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.max_age') > 0 ? '' : ' 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 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,
  );
  return parent::buildForm($form, $form_state);
}