You are here

public function NodeRevisionsByBundleForm::submitForm in Node Revisions Autoclean 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 FormInterface::submitForm

File

src/Form/NodeRevisionsByBundleForm.php, line 151

Class

NodeRevisionsByBundleForm
Class NodeRevisionsByBundleForm.

Namespace

Drupal\node_revisions_autoclean\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this->configFactory
    ->getEditable('node_revisions_autoclean.settings');
  $values = $form_state
    ->getValues();
  $enable_on_cron = (int) $form_state
    ->getValue('enable_on_cron');
  $config
    ->set('enable_on_cron', $enable_on_cron);
  $enable_on_node_update = (int) $form_state
    ->getValue('enable_on_node_update');
  $config
    ->set('enable_on_node_update', $enable_on_node_update);
  foreach ($values as $key => $val) {
    if (strpos($key, 'interval__') === 0) {
      $machine_name = str_replace('interval__', '', $key);
      $key = str_replace('__', '.', $key);
      if ($form_state
        ->getValue('node_enable_date_' . $machine_name)) {
        $config
          ->set($key, "{$val}");
      }
      else {
        $config
          ->set($key, '0');
      }
    }
    elseif (strpos($key, 'node__') === 0) {
      $key = str_replace('__', '.', $key);
      $config
        ->set($key, (int) $val);
    }
  }
  $config
    ->save(TRUE);
  $this
    ->messenger()
    ->addMessage($this
    ->t('Node revisions settings have been updated.'));
}