function FileTransferAuthorizeForm::validateForm

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php \Drupal\Core\FileTransfer\Form\FileTransferAuthorizeForm::validateForm()
  2. 8.9.x core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php \Drupal\Core\FileTransfer\Form\FileTransferAuthorizeForm::validateForm()
  3. 10 core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php \Drupal\Core\FileTransfer\Form\FileTransferAuthorizeForm::validateForm()

Overrides FormBase::validateForm

File

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

Class

FileTransferAuthorizeForm
Provides the file transfer authorization form.

Namespace

Drupal\Core\FileTransfer\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
    // Only validate the form if we have collected all of the user input and are
    // ready to proceed with updating or installing.
    if ($form_state->getTriggeringElement()['#name'] != 'process_updates') {
        return;
    }
    if ($form_connection_settings = $form_state->getValue('connection_settings')) {
        $backend = $form_connection_settings['authorize_filetransfer_default'];
        $filetransfer = $this->getFiletransfer($backend, $form_connection_settings[$backend]);
        try {
            if (!$filetransfer) {
                throw new \Exception("The connection protocol '{$backend}' does not exist.");
            }
            $filetransfer->connect();
        } catch (\Exception $e) {
            // The format of this error message is similar to that used on the
            // database connection form in the installer.
            $form_state->setErrorByName('connection_settings', $this->t('Failed to connect to the server. The server reports the following message: <p class="error">@message</p> For more help adding or updating code on your server, see the <a href=":handbook_url">handbook</a>.', [
                '@message' => $e->getMessage(),
                ':handbook_url' => 'https://www.drupal.org/docs/extending-drupal/overview',
            ]));
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.