public function ConfigPartialExportForm::buildForm in Config Partial Export 8
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
- src/
Form/ ConfigPartialExportForm.php, line 106
Class
- ConfigPartialExportForm
- Construct the storage changes in a configuration synchronization form.
Namespace
Drupal\config_partial_export\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$snapshot_comparer = new StorageComparer($this->activeStorage, $this->snapshotStorage, $this->configManager);
$change_list = [];
if ($snapshot_comparer
->createChangelist()
->hasChanges()) {
$this
->messenger()
->addWarning($this
->t('Your current configuration has changed.'));
foreach ($snapshot_comparer
->getAllCollectionNames() as $collection) {
foreach ($snapshot_comparer
->getChangelist(NULL, $collection) as $config_names) {
if (empty($config_names)) {
continue;
}
foreach ($config_names as $config_name) {
$change_list[$config_name]['name'] = $config_name;
}
}
}
}
if (empty($change_list)) {
$user_input = $form_state
->getUserInput();
if (isset($user_input['change_list'])) {
$change_list = $user_input['change_list'];
}
}
ksort($change_list);
$form['change_list'] = [
'#type' => 'tableselect',
'#header' => [
'name' => $this
->t('Name'),
],
'#options' => $change_list,
];
$form['description'] = [
'#markup' => '<p><b>' . $this
->t('Use the export button to download the selected files listed above.') . '</b></p>',
];
$form['addSystemSiteInfo'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Add system.site info'),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Export'),
];
$last_selection = $this->state
->get('config_partial_export_form');
$current_user_id = $this
->currentUser()
->id();
if (!empty($last_selection[$current_user_id])) {
$current_user_last_selection = $last_selection[$current_user_id];
$form['change_list']['#default_value'] = $current_user_last_selection['status_checkboxes_all'];
$form['addSystemSiteInfo']['#default_value'] = $current_user_last_selection['status_checkbox_system'];
}
return $form;
}