public function FileTransferAuthorizeForm::buildForm 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::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- core/
lib/ Drupal/ Core/ FileTransfer/ Form/ FileTransferAuthorizeForm.php, line 55 - Contains \Drupal\Core\FileTransfer\Form\FileTransferAuthorizeForm.
Class
- FileTransferAuthorizeForm
- Provides the file transfer authorization form.
Namespace
Drupal\Core\FileTransfer\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// Get all the available ways to transfer files.
if (empty($_SESSION['authorize_filetransfer_info'])) {
drupal_set_message($this
->t('Unable to continue, no available methods of file transfer'), 'error');
return array();
}
$available_backends = $_SESSION['authorize_filetransfer_info'];
if (!$this
->getRequest()
->isSecure()) {
$form['information']['https_warning'] = array(
'#prefix' => '<div class="messages messages--error">',
'#markup' => $this
->t('WARNING: You are not using an encrypted connection, so your password will be sent in plain text. <a href=":https-link">Learn more</a>.', array(
':https-link' => 'https://www.drupal.org/https-information',
)),
'#suffix' => '</div>',
);
}
// Decide on a default backend.
if ($authorize_filetransfer_default = $form_state
->getValue(array(
'connection_settings',
'authorize_filetransfer_default',
))) {
}
elseif ($authorize_filetransfer_default = $this
->config('system.authorize')
->get('filetransfer_default')) {
}
else {
$authorize_filetransfer_default = key($available_backends);
}
$form['information']['main_header'] = array(
'#prefix' => '<h3>',
'#markup' => $this
->t('To continue, provide your server connection details'),
'#suffix' => '</h3>',
);
$form['connection_settings']['#tree'] = TRUE;
$form['connection_settings']['authorize_filetransfer_default'] = array(
'#type' => 'select',
'#title' => $this
->t('Connection method'),
'#default_value' => $authorize_filetransfer_default,
'#weight' => -10,
);
/*
* Here we create two submit buttons. For a JS enabled client, they will
* only ever see submit_process. However, if a client doesn't have JS
* enabled, they will see submit_connection on the first form (when picking
* what filetransfer type to use, and submit_process on the second one (which
* leads to the actual operation).
*/
$form['submit_connection'] = array(
'#prefix' => "<br style='clear:both'/>",
'#name' => 'enter_connection_settings',
'#type' => 'submit',
'#value' => $this
->t('Enter connection settings'),
'#weight' => 100,
);
$form['submit_process'] = array(
'#name' => 'process_updates',
'#type' => 'submit',
'#value' => $this
->t('Continue'),
'#weight' => 100,
);
// Build a container for each connection type.
foreach ($available_backends as $name => $backend) {
$form['connection_settings']['authorize_filetransfer_default']['#options'][$name] = $backend['title'];
$form['connection_settings'][$name] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
"filetransfer-{$name}",
'filetransfer',
),
),
'#states' => array(
'visible' => array(
'select[name="connection_settings[authorize_filetransfer_default]"]' => array(
'value' => $name,
),
),
),
);
// We can't use #prefix on the container itself since then the header won't
// be hidden and shown when the containers are being manipulated via JS.
$form['connection_settings'][$name]['header'] = array(
'#markup' => '<h4>' . $this
->t('@backend connection settings', array(
'@backend' => $backend['title'],
)) . '</h4>',
);
$form['connection_settings'][$name] += $this
->addConnectionSettings($name);
// Start non-JS code.
if ($form_state
->getValue(array(
'connection_settings',
'authorize_filetransfer_default',
)) == $name) {
// Change the submit button to the submit_process one.
$form['submit_process']['#attributes'] = array();
unset($form['submit_connection']);
// Activate the proper filetransfer settings form.
$form['connection_settings'][$name]['#attributes']['style'] = 'display:block';
// Disable the select box.
$form['connection_settings']['authorize_filetransfer_default']['#disabled'] = TRUE;
// Create a button for changing the type of connection.
$form['connection_settings']['change_connection_type'] = array(
'#name' => 'change_connection_type',
'#type' => 'submit',
'#value' => $this
->t('Change connection type'),
'#weight' => -5,
'#attributes' => array(
'class' => array(
'filetransfer-change-connection-type',
),
),
);
}
// End non-JS code.
}
return $form;
}