You are here

public function CleanerSettingsForm::buildForm in Cleaner 8

Same name and namespace in other branches
  1. 8.2 src/Form/CleanerSettingsForm.php \Drupal\cleaner\Form\CleanerSettingsForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/CleanerSettingsForm.php, line 160

Class

CleanerSettingsForm
Class CleanerSettingsForm.

Namespace

Drupal\cleaner\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Get config handler.
  $conf = $this
    ->config(CLEANER_SETTINGS);

  // Prepare Yes/No options array.
  $yes_no = [
    $this
      ->t('No:'),
    $this
      ->t('Yes:'),
  ];

  // Attach the "cleaner-admin" library for some admin page styling.
  $form['cleaner']['#attached']['library'][] = 'cleaner/cleaner-admin';

  // Cron interval settings.
  $form['cleaner']['cleaner_cron'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Run interval'),
    '#options' => array_merge([
      0 => $this
        ->t('Every time'),
    ], self::$intervals),
    '#default_value' => (int) $conf
      ->get('cleaner_cron'),
    '#description' => $this
      ->t('This is how often the options below will occur. <br> The actions will occur on the next Cron run after this interval expires. <br>"Every time" means on every Cron run.'),
  ];

  // Cache clearing settings.
  $form['cleaner']['cleaner_clear_cache'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Clean up cache'),
    '#default_value' => (int) $conf
      ->get('cleaner_clear_cache'),
    '#description' => $this
      ->getCacheTablesTable(),
  ];

  // Additional tables clearing settings.
  $form['cleaner']['cleaner_additional_tables'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Additional tables to clear'),
    '#default_value' => (string) $conf
      ->get('cleaner_additional_tables'),
    '#description' => $this
      ->t('A comma separated list of table names which also needs to be cleared.'),
  ];

  // Watchdog clearing settings.
  $form['cleaner']['cleaner_empty_watchdog'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Clean up Watchdog'),
    '#default_value' => (int) $conf
      ->get('cleaner_empty_watchdog'),
    '#description' => $this
      ->t('There is a standard setting for controlling Watchdog contents. This is more useful for test sites.'),
  ];

  // Get session settings.
  $session_settings = self::getSessionSettings();

  // Sessions clearing settings.
  $form['cleaner']['cleaner_clean_sessions'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Clean up Sessions table'),
    '#default_value' => (int) $conf
      ->get('cleaner_clean_sessions'),
    '#description' => $this
      ->t('The sessions table can quickly become full with old, abandoned sessions. <br>This will delete all sessions older than @interval (as set by your site administrator). <br>There are currently @count such sessions.', [
      '@interval' => $session_settings['lifetime'],
      '@count' => $session_settings['old_sessions'],
    ]),
  ];

  // We can only offer OPTIMIZE to MySQL users.
  if (\Drupal::database()
    ->driver() == 'mysql') {

    // Database(MySQL) optimizing settings.
    $form['cleaner']['cleaner_optimize_db'] = [
      '#type' => 'radios',
      '#options' => $yes_no + [
        '2' => $this
          ->t('Local only:'),
      ],
      '#title' => $this
        ->t('Optimize tables with "overhead" space'),
      '#default_value' => (int) $conf
        ->get('cleaner_optimize_db'),
      '#description' => $this
        ->t('The module will compress (optimize) all database tables with unused space.<br><strong>NOTE</strong>: During an optimization, the table will locked against any other activity; on a high vloume site, this may be undesirable. "Local only" means do not replicate the optimization (if it is being done).'),
    ];
  }
  return parent::buildForm($form, $form_state);
}