You are here

public function NodeViewCountSettingsForm::submitForm in Node view count 8

Form submission handler.

Parameters

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

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

Overrides ConfigFormBase::submitForm

File

src/Form/NodeViewCountSettingsForm.php, line 246

Class

NodeViewCountSettingsForm
Configure nodeviewcount settings.

Namespace

Drupal\nodeviewcount\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $counting_user_roles = array_filter($form_state
    ->getValue('user_roles'));
  $excluded_user_roles = array_filter($form_state
    ->getValue('excluded_user_roles'));
  foreach ($counting_user_roles as $key => $couting_user_role) {
    if ($couting_user_role) {
      unset($excluded_user_roles[$key]);
    }
  }
  $this
    ->config('nodeviewcount.settings')
    ->set('node_types', array_keys(array_filter($form_state
    ->getValue('node_types'))))
    ->set('view_modes', array_keys(array_filter($form_state
    ->getValue('view_modes'))))
    ->set('user_roles', array_keys($counting_user_roles))
    ->set('excluded_user_roles', array_keys($excluded_user_roles))
    ->set('logs_life_time', (int) $form_state
    ->getValue('logs_life_time'))
    ->save(TRUE);
  $this->cacheTagsInvalidator
    ->invalidateTags([
    'node_view',
  ]);
  parent::submitForm($form, $form_state);
}