You are here

public function NodeViewCountSettingsForm::buildForm in Node view count 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/NodeViewCountSettingsForm.php, line 100

Class

NodeViewCountSettingsForm
Configure nodeviewcount settings.

Namespace

Drupal\nodeviewcount\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('nodeviewcount.settings');
  $form['node_types'] = [
    '#title' => $this
      ->t('Node types'),
    '#description' => $this
      ->t('Choose content types to count views.'),
    '#type' => 'checkboxes',
    '#options' => $this
      ->getNodeTypesOptions(),
    '#default_value' => $config
      ->get('node_types'),
  ];
  $form['view_modes'] = [
    '#title' => $this
      ->t('View modes'),
    '#description' => $this
      ->t('Choose node view modes to count views.'),
    '#type' => 'checkboxes',
    '#options' => $this
      ->getNodeViewModesOptions(),
    '#default_value' => $config
      ->get('view_modes'),
  ];
  $form['user_roles'] = [
    '#title' => $this
      ->t('User roles'),
    '#description' => $this
      ->t('Choose user roles for counting node views.'),
    '#type' => 'checkboxes',
    '#options' => $this
      ->getRoleNamesOptions($config
      ->get('excluded_user_roles')),
    '#default_value' => $config
      ->get('user_roles'),
  ];
  $form['excluded_user_roles'] = [
    '#title' => $this
      ->t('Excluded user roles'),
    '#description' => $this
      ->t('Choose user roles which will be excluded from node views counting.'),
    '#type' => 'checkboxes',
    '#options' => $this
      ->getRoleNamesOptions($config
      ->get('user_roles')),
    '#default_value' => $config
      ->get('excluded_user_roles'),
  ];
  $form['logs_life_time'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Discard node views logs older than'),
    '#default_value' => $config
      ->get('logs_life_time'),
    '#options' => $this
      ->getLogsLifeTimeOptions(),
    '#description' => $this
      ->t('Older log entries will be automatically discarded, (Requires a correctly configured <a href="@cron">cron maintenance task</a>.). Pick Never if you dont want logs to be deleted.', [
      '@cron' => Url::fromRoute('system.status')
        ->toString(),
    ]),
  ];
  return parent::buildForm($form, $form_state);
}