You are here

public function LoggerSettingsForm::buildForm in Ultimate Cron 8.2

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/LoggerSettingsForm.php, line 29

Class

LoggerSettingsForm
Form for logger settings.

Namespace

Drupal\ultimate_cron\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('ultimate_cron.settings');

  // Setup vertical tabs.
  $form['settings_tabs'] = [
    '#type' => 'vertical_tabs',
  ];

  // Settings for Cache logger.
  $form['cache'] = [
    '#type' => 'details',
    '#title' => t('Cache'),
    '#group' => 'settings_tabs',
    '#tree' => TRUE,
  ];
  $form['cache']['bin'] = array(
    '#type' => 'textfield',
    '#title' => t('Cache bin'),
    '#description' => t('Select which cache bin to use for storing logs.'),
    '#default_value' => $config
      ->get('logger.cache.bin'),
    '#fallback' => TRUE,
    '#required' => TRUE,
  );
  $form['cache']['timeout'] = array(
    '#type' => 'textfield',
    '#title' => t('Cache timeout'),
    '#description' => t('Seconds before cache entry expires (0 = never, -1 = on next general cache wipe).'),
    '#default_value' => $config
      ->get('logger.cache.timeout'),
    '#fallback' => TRUE,
    '#required' => TRUE,
  );

  // Settings for Database logger.
  $form['database'] = [
    '#type' => 'details',
    '#title' => t('Database'),
    '#group' => 'settings_tabs',
    '#tree' => TRUE,
  ];
  $options['method'] = [
    1 => t('Disabled'),
    2 => t('Remove logs older than a specified age'),
    3 => t('Retain only a specific amount of log entries'),
  ];
  $form['database']['method'] = array(
    '#type' => 'select',
    '#title' => t('Log entry cleanup method'),
    '#description' => t('Select which method to use for cleaning up logs.'),
    '#options' => $options['method'],
    '#default_value' => $config
      ->get('logger.database.method'),
    '#fallback' => TRUE,
    '#required' => TRUE,
  );
  $states = array(
    'expire' => array(),
    'retain' => array(),
  );
  $form['database']['method_expire'] = array(
    '#type' => 'fieldset',
    '#title' => t('Remove logs older than a specified age'),
  ) + $states['expire'];
  $form['database']['method_expire']['expire'] = array(
    '#type' => 'textfield',
    '#title' => t('Log entry expiration'),
    '#description' => t('Remove log entries older than X seconds.'),
    '#default_value' => $config
      ->get('logger.database.method_expire.expire'),
    '#fallback' => TRUE,
    '#required' => TRUE,
  ) + $states['expire'];
  $form['database']['method_retain'] = array(
    '#type' => 'fieldset',
    '#title' => t('Retain only a specific amount of log entries'),
  ) + $states['retain'];
  $form['database']['method_retain']['retain'] = array(
    '#type' => 'textfield',
    '#title' => t('Retain logs'),
    '#description' => t('Retain X amount of log entries.'),
    '#default_value' => $config
      ->get('logger.database.method_retain.retain'),
    '#fallback' => TRUE,
    '#required' => TRUE,
  ) + $states['retain'];
  return parent::buildForm($form, $form_state);
}