function CredentialForm::buildForm
Same name in other branches
- 9 core/modules/migrate_drupal_ui/src/Form/CredentialForm.php \Drupal\migrate_drupal_ui\Form\CredentialForm::buildForm()
- 10 core/modules/migrate_drupal_ui/src/Form/CredentialForm.php \Drupal\migrate_drupal_ui\Form\CredentialForm::buildForm()
- 11.x core/modules/migrate_drupal_ui/src/Form/CredentialForm.php \Drupal\migrate_drupal_ui\Form\CredentialForm::buildForm()
Overrides MigrateUpgradeFormBase::buildForm
File
-
core/
modules/ migrate_drupal_ui/ src/ Form/ CredentialForm.php, line 81
Class
- CredentialForm
- Migrate Upgrade database credential form.
Namespace
Drupal\migrate_drupal_ui\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
if ($this->store
->get('step') != 'credential') {
return $this->restartUpgradeForm();
}
$form = parent::buildForm($form, $form_state);
$form['actions']['submit']['#value'] = $this->t('Review upgrade');
$form['#title'] = $this->t('Drupal Upgrade');
$drivers = $this->getDatabaseTypes();
$drivers_keys = array_keys($drivers);
$default_driver = current($drivers_keys);
$default_options = [];
$form['help'] = [
'#type' => 'item',
'#description' => $this->t('Provide the information to access the Drupal site you want to upgrade. Files can be imported into the upgraded site as well. See the <a href=":url">Upgrade documentation for more detailed instructions</a>.', [
':url' => 'https://www.drupal.org/upgrade/migrate',
]),
];
$form['version'] = [
'#type' => 'radios',
'#default_value' => 7,
'#title' => $this->t('Drupal version of the source site'),
'#options' => [
'6' => $this->t('Drupal 6'),
'7' => $this->t('Drupal 7'),
],
'#required' => TRUE,
];
$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);
unset($form['database']['settings'][$key]['advanced_options']['prefix']['#description']);
// This is a multi-step form and is not rebuilt during submission so
// #limit_validation_errors is not used. The database and username fields
// for mysql and pgsql must not be required.
$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']['d6_source_base_path'] = [
'#type' => 'textfield',
'#title' => $this->t('Document root for files'),
'#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 (for example http://example.com).'),
'#states' => [
'visible' => [
':input[name="version"]' => [
'value' => '6',
],
],
],
'#element_validate' => [
'::validatePaths',
],
];
$form['source']['source_base_path'] = [
'#type' => 'textfield',
'#title' => $this->t('Document root for public files'),
'#description' => $this->t('To import public files from your current Drupal site, enter a local file directory containing your site (e.g. /var/www/docroot), or your site address (for example http://example.com).'),
'#states' => [
'visible' => [
':input[name="version"]' => [
'value' => '7',
],
],
],
'#element_validate' => [
'::validatePaths',
],
];
$form['source']['source_private_file_path'] = [
'#type' => 'textfield',
'#title' => $this->t('Document root for private files'),
'#default_value' => '',
'#description' => $this->t('To import private files from your current Drupal site, enter a local file directory containing your site (e.g. /var/www/docroot).'),
'#states' => [
'visible' => [
':input[name="version"]' => [
'value' => '7',
],
],
],
'#element_validate' => [
'::validatePaths',
],
];
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.