You are here

public function SecuritytxtConfigureForm::submitForm in Security.txt 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/SecuritytxtConfigureForm.php, line 151

Class

SecuritytxtConfigureForm
Configure the security.txt file.

Namespace

Drupal\securitytxt\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $enabled = $form_state
    ->getValue('enabled');
  $contact_email = $form_state
    ->getValue('contact_email');
  $contact_phone = $form_state
    ->getValue('contact_phone');
  $contact_url = $form_state
    ->getValue('contact_url');
  $encryption_key_url = $form_state
    ->getValue('encryption_key_url');
  $policy_url = $form_state
    ->getValue('policy_url');
  $acknowledgement_url = $form_state
    ->getValue('acknowledgement_url');

  /* Warn if contact URL is not loaded over HTTPS */
  if ($contact_url != '' && substr($contact_url, 0, 8) !== 'https://') {
    $this
      ->messenger()
      ->addWarning($this
      ->t('Your contact URL should really be loaded over HTTPS.'));
  }

  /* Warn if encryption URL is not loaded over HTTPS */
  if ($encryption_key_url != '' && substr($encryption_key_url, 0, 8) !== 'https://') {
    $this
      ->messenger()
      ->addWarning($this
      ->t('Your public key URL should really be loaded over HTTPS.'));
  }

  /* Message the user to proceed to the sign page if they have enabled security.txt */
  if ($enabled) {
    $this
      ->messenger()
      ->addStatus($this
      ->t('You should now <a href=":sign">sign your security.txt file</a>.', [
      ':sign' => Url::fromRoute('securitytxt.sign')
        ->toString(),
    ]));
  }

  /* Save the configuration */
  $this->settings
    ->set('enabled', $enabled)
    ->set('contact_email', $contact_email)
    ->set('contact_phone', $contact_phone)
    ->set('contact_url', $contact_url)
    ->set('encryption_key_url', $encryption_key_url)
    ->set('policy_url', $policy_url)
    ->set('acknowledgement_url', $acknowledgement_url)
    ->save();
  parent::submitForm($form, $form_state);
}