You are here

public function SettingsForm::submitForm in Security Review 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/SettingsForm.php, line 226

Class

SettingsForm
Settings page for Security Review.

Namespace

Drupal\security_review\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Frequently used configuration items.
  $check_settings = $this
    ->config('security_review.checks');

  // Save that the module has been configured.
  $this->securityReview
    ->setConfigured(TRUE);

  // Save the new untrusted roles.
  $untrusted_roles = array_keys(array_filter($form_state
    ->getValue('untrusted_roles')));
  $this->securityReview
    ->setUntrustedRoles($untrusted_roles);

  // Save the new logging setting.
  $logging = $form_state
    ->getValue('logging') == 1;
  $this->securityReview
    ->setLogging($logging);

  // Skip selected checks.
  $skipped = array_keys(array_filter($form_state
    ->getValue('skip')));
  foreach ($this->checklist
    ->getChecks() as $check) {
    if (in_array($check
      ->id(), $skipped)) {
      $check
        ->skip();
    }
    else {
      $check
        ->enable();
    }
  }

  // Save the check-specific settings.
  if (isset($form['advanced']['check_specific'])) {
    $check_specific_values = $form_state
      ->getValue('check_specific');
    foreach ($check_specific_values as $id => $values) {

      // Get corresponding Check.
      $check = $this->checklist
        ->getCheckById($id);

      // Submit parameters.
      $check_form =& $form['advanced']['check_specific'][$id]['form'];
      $check_form_values = $check_specific_values[$id]['form'];

      // Submit.
      $check
        ->settings()
        ->submitForm($check_form, $check_form_values);
    }
  }

  // Commit the settings.
  $check_settings
    ->save();

  // Finish submitting the form.
  parent::submitForm($form, $form_state);
}