public function MigrateUpgradeForm::buildCredentialForm in Migrate Upgrade 8
Builds the database credential form and adds file location information.
This is largely borrowed from \Drupal\Core\Installer\Form\SiteSettingsForm.
@todo Private files directory not yet implemented, depends on https://www.drupal.org/node/2547125.
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.
1 call to MigrateUpgradeForm::buildCredentialForm()
- MigrateUpgradeForm::buildForm in src/
Form/ MigrateUpgradeForm.php - Form constructor.
File
- src/
Form/ MigrateUpgradeForm.php, line 805 - Contains \Drupal\migrate_upgrade\Form\MigrateUpgradeForm.
Class
- MigrateUpgradeForm
- Defines a multi-step form for performing direct site upgrades.
Namespace
Drupal\migrate_upgrade\FormCode
public function buildCredentialForm(array $form, FormStateInterface $form_state) {
$form['#title'] = $this
->t('Drupal Upgrade');
$drivers = $this
->getDatabaseTypes();
$drivers_keys = array_keys($drivers);
// @todo https://www.drupal.org/node/2678510 Because this is a multi-step
// form, the form is not rebuilt during submission. Ideally we would get
// the chosen driver from form input, if available, in order to use
// #limit_validation_errors in the same way
// \Drupal\Core\Installer\Form\SiteSettingsForm does.
$default_driver = current($drivers_keys);
$default_options = [];
$form['database'] = [
'#type' => 'details',
'#title' => $this
->t('Source database'),
'#description' => $this
->t('Provide credentials for the database of the Drupal site you want to upgrade.'),
'#open' => TRUE,
];
$form['database']['driver'] = [
'#type' => 'radios',
'#title' => $this
->t('Database type'),
'#required' => TRUE,
'#default_value' => $default_driver,
];
if (count($drivers) == 1) {
$form['database']['driver']['#disabled'] = TRUE;
}
// Add driver-specific configuration options.
foreach ($drivers as $key => $driver) {
$form['database']['driver']['#options'][$key] = $driver
->name();
$form['database']['settings'][$key] = $driver
->getFormOptions($default_options);
// @todo https://www.drupal.org/node/2678510 Using
// #limit_validation_errors in the submit does not work so it is not
// possible to require the database and username for mysql and pgsql.
// This is because this is a multi-step form.
$form['database']['settings'][$key]['database']['#required'] = FALSE;
$form['database']['settings'][$key]['username']['#required'] = FALSE;
$form['database']['settings'][$key]['#prefix'] = '<h2 class="js-hide">' . $this
->t('@driver_name settings', [
'@driver_name' => $driver
->name(),
]) . '</h2>';
$form['database']['settings'][$key]['#type'] = 'container';
$form['database']['settings'][$key]['#tree'] = TRUE;
$form['database']['settings'][$key]['advanced_options']['#parents'] = [
$key,
];
$form['database']['settings'][$key]['#states'] = [
'visible' => [
':input[name=driver]' => [
'value' => $key,
],
],
];
// Move the host fields out of advanced settings.
if (isset($form['database']['settings'][$key]['advanced_options']['host'])) {
$form['database']['settings'][$key]['host'] = $form['database']['settings'][$key]['advanced_options']['host'];
$form['database']['settings'][$key]['host']['#title'] = 'Database host';
$form['database']['settings'][$key]['host']['#weight'] = -1;
unset($form['database']['settings'][$key]['database']['#default_value']);
unset($form['database']['settings'][$key]['advanced_options']['host']);
}
}
$form['source'] = [
'#type' => 'details',
'#title' => $this
->t('Source files'),
'#open' => TRUE,
];
$form['source']['source_base_path'] = [
'#type' => 'textfield',
'#title' => $this
->t('Files directory'),
'#description' => $this
->t('To import files from your current Drupal site, enter a local file directory containing your site (e.g. /var/www/docroot), or your site address (e.g. http://example.com).'),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['save'] = [
'#type' => 'submit',
'#value' => $this
->t('Review upgrade'),
'#button_type' => 'primary',
'#validate' => [
'::validateCredentialForm',
],
'#submit' => [
'::submitCredentialForm',
],
];
return $form;
}