You are here

public function IpAnonSettings::buildForm in IP Anonymize 8

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/IpAnonSettings.php, line 90

Class

IpAnonSettings
Settings form for ip_anon module.

Namespace

Drupal\ip_anon\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('ip_anon.settings');
  $form['policy'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Retention policy'),
    '#options' => [
      $this
        ->t('Preserve IP addresses'),
      $this
        ->t('Anonymize IP addresses'),
    ],
    '#description' => $this
      ->t('This setting may be used to temporarily disable IP anonymization.'),
    '#default_value' => $config
      ->get('policy'),
  ];
  $form['period'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Retention period'),
    '#description' => $this
      ->t('IP addresses older than the retention period will be anonymized.'),
  ];
  $intervals = [
    0,
    30,
    60,
    120,
    180,
    300,
    600,
    900,
    1800,
    2700,
    3600,
    5400,
    7200,
    10800,
    21600,
    32400,
    43200,
    64800,
    86400,
    172800,
    259200,
    345600,
    604800,
    1209600,
    2419200,
    4838400,
    9676800,
    31536000,
    2147483647,
  ];
  $options = array_combine($intervals, array_map([
    $this->dateFormatter,
    'formatInterval',
  ], $intervals));
  module_load_include('inc', 'ip_anon');
  foreach (ip_anon_tables() as $table => $columns) {
    $form['period']["period_{$table}"] = [
      '#type' => 'select',
      '#title' => $this
        ->t('@table table', [
        '@table' => $table,
      ]),
      '#options' => $options,
      '#default_value' => $config
        ->get("period_{$table}"),
      '#description' => new FormattableMarkup('@description', [
        '@description' => $this
          ->getTableDescription($table),
      ]),
    ];
  }
  return parent::buildForm($form, $form_state);
}