You are here

public function CreditSettingsForm::submitForm in Ubercart 8.4

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

payment/uc_credit/src/Form/CreditSettingsForm.php, line 127

Class

CreditSettingsForm
Credit card settings form.

Namespace

Drupal\uc_credit\Form

Code

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

  // Check to see if we need to create an encryption key file.
  if ($form_state
    ->getValue('update_cc_encrypt_dir')) {
    $key_path = $form_state
      ->getValue('uc_credit_encryption_path');
    $key_file = $key_path . '/' . UC_CREDIT_KEYFILE_NAME;
    if (!file_exists($key_file)) {
      if (!($file = fopen($key_file, 'wb'))) {
        $this
          ->messenger()
          ->addError($this
          ->t('Credit card encryption key file creation failed for file @file. Check your filepath settings and directory permissions.', [
          '@file' => $key_file,
        ]));
        $this
          ->logger('uc_credit')
          ->error('Credit card encryption key file creation failed for file @file. Check your filepath settings and directory permissions.', [
          '@file' => $key_file,
        ]);
      }
      else {

        // Replacement key generation suggested by Barry Jaspan
        // for increased security.
        fwrite($file, md5(\Drupal::csrfToken()
          ->get(serialize($_REQUEST) . serialize($_SERVER) . REQUEST_TIME)));
        fclose($file);
        $this
          ->messenger()
          ->addMessage($this
          ->t('Credit card encryption key file generated. Card data will now be encrypted.'));
        $this
          ->logger('uc_credit')
          ->notice('Credit card encryption key file generated. Card data will now be encrypted.');
      }
    }
  }
  $this
    ->config('uc_credit.settings')
    ->set('encryption_path', $form_state
    ->getValue('uc_credit_encryption_path'))
    ->save();
}