You are here

public function SiteVerifyAdminForm::submitForm in Site verification 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/SiteVerifyAdminForm.php, line 189

Class

SiteVerifyAdminForm
Configure cron settings for this site.

Namespace

Drupal\site_verify\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $storage = $form_state
    ->getStorage();
  if ($storage['step'] == 1) {

    // Send the form to step 2 (verification details).
    $form_state
      ->setStorage([
      'record' => [
        'engine' => \Drupal::service('site_verify_service')
          ->siteVerifyEngineLoad($form_state
          ->getValue('engine')),
      ],
      'step' => 2,
    ]);
    $form_state
      ->setRebuild(TRUE);
  }
  else {

    // Save the verification to the database.
    \Drupal::database()
      ->merge('site_verify')
      ->key('svid', $form_state
      ->getValue('svid'))
      ->fields([
      'engine' => $form_state
        ->getValue('engine'),
      'file' => $form_state
        ->getValue('file'),
      'file_contents' => $form_state
        ->getValue('file_contents'),
      'meta' => $form_state
        ->getValue('meta'),
    ])
      ->execute();
    $this
      ->messenger()
      ->addStatus(t('Verification saved.'));
    $form_state
      ->setStorage([]);
    $form_state
      ->setRebuild(NULL);
    $form_state
      ->setRedirect('site_verify.verifications_list');

    // Set the menu to be rebuilt.
    \Drupal::service('router.builder')
      ->setRebuildNeeded();
  }
}