You are here

public function FileTransferAuthorizeForm::submitForm in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php \Drupal\Core\FileTransfer\Form\FileTransferAuthorizeForm::submitForm()
  2. 10 core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php \Drupal\Core\FileTransfer\Form\FileTransferAuthorizeForm::submitForm()

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

core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php, line 189

Class

FileTransferAuthorizeForm
Provides the file transfer authorization form.

Namespace

Drupal\Core\FileTransfer\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $form_connection_settings = $form_state
    ->getValue('connection_settings');
  switch ($form_state
    ->getTriggeringElement()['#name']) {
    case 'process_updates':

      // Save the connection settings to the DB.
      $filetransfer_backend = $form_connection_settings['authorize_filetransfer_default'];

      // If the database is available then try to save our settings. We have
      // to make sure it is available since this code could potentially (will
      // likely) be called during the installation process, before the
      // database is set up.
      try {
        $filetransfer = $this
          ->getFiletransfer($filetransfer_backend, $form_connection_settings[$filetransfer_backend]);

        // Now run the operation.
        $response = $this
          ->runOperation($filetransfer);
        if ($response instanceof Response) {
          $form_state
            ->setResponse($response);
        }
      } catch (\Exception $e) {

        // If there is no database available, we don't care and just skip
        // this part entirely.
      }
      break;
    case 'enter_connection_settings':
      $form_state
        ->setRebuild();
      break;
    case 'change_connection_type':
      $form_state
        ->setRebuild();
      $form_state
        ->unsetValue([
        'connection_settings',
        'authorize_filetransfer_default',
      ]);
      break;
  }
}