public function FileTransferAuthorizeForm::submitForm in Zircon Profile 8.0
Same name and namespace in other branches
- 8 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 193 - Contains \Drupal\Core\FileTransfer\Form\FileTransferAuthorizeForm.
Class
- FileTransferAuthorizeForm
- Provides the file transfer authorization form.
Namespace
Drupal\Core\FileTransfer\FormCode
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 {
$connection_settings = array();
foreach ($form_connection_settings[$filetransfer_backend] as $key => $value) {
// We do *not* want to store passwords in the database, unless the
// backend explicitly says so via the magic #filetransfer_save form
// property. Otherwise, we store everything that's not explicitly
// marked with #filetransfer_save set to FALSE.
if (!isset($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save'])) {
if ($form['connection_settings'][$filetransfer_backend][$key]['#type'] != 'password') {
$connection_settings[$key] = $value;
}
}
elseif ($form['connection_settings'][$filetransfer_backend][$key]['#filetransfer_save']) {
$connection_settings[$key] = $value;
}
}
// Set this one as the default authorize method.
$this
->config('system.authorize')
->set('filetransfer_default', $filetransfer_backend);
// Save the connection settings minus the password.
$this
->config('system.authorize')
->set('filetransfer_connection_settings_' . $filetransfer_backend, $connection_settings);
$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(array(
'connection_settings',
'authorize_filetransfer_default',
));
break;
}
}