function ConfigSingleExportForm::buildForm
Same name in other branches
- 8.9.x core/modules/config/src/Form/ConfigSingleExportForm.php \Drupal\config\Form\ConfigSingleExportForm::buildForm()
- 10 core/modules/config/src/Form/ConfigSingleExportForm.php \Drupal\config\Form\ConfigSingleExportForm::buildForm()
- 11.x core/modules/config/src/Form/ConfigSingleExportForm.php \Drupal\config\Form\ConfigSingleExportForm::buildForm()
Overrides FormInterface::buildForm
File
-
core/
modules/ config/ src/ Form/ ConfigSingleExportForm.php, line 77
Class
- ConfigSingleExportForm
- Provides a form for exporting a single configuration file.
Namespace
Drupal\config\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $config_type = NULL, $config_name = NULL) {
$form['#prefix'] = '<div id="js-config-form-wrapper">';
$form['#suffix'] = '</div>';
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type => $definition) {
if ($definition->entityClassImplements(ConfigEntityInterface::class)) {
$this->definitions[$entity_type] = $definition;
}
}
$entity_types = array_map(function (EntityTypeInterface $definition) {
return $definition->getLabel();
}, $this->definitions);
// Sort the entity types by label, then add the simple config to the top.
uasort($entity_types, 'strnatcasecmp');
$config_types = [
'system.simple' => $this->t('Simple configuration'),
] + $entity_types;
$form['config_type'] = [
'#title' => $this->t('Configuration type'),
'#type' => 'select',
'#options' => $config_types,
'#default_value' => $config_type,
'#ajax' => [
'callback' => '::updateConfigurationType',
'wrapper' => 'js-config-form-wrapper',
],
];
$default_type = $form_state->getValue('config_type', $config_type);
$form['config_name'] = [
'#title' => $this->t('Configuration name'),
'#type' => 'select',
'#options' => $this->findConfiguration($default_type),
'#default_value' => $config_name,
'#prefix' => '<div id="edit-config-type-wrapper">',
'#suffix' => '</div>',
'#ajax' => [
'callback' => '::updateExport',
'wrapper' => 'edit-export-wrapper',
],
];
$form['export'] = [
'#title' => $this->t('Here is your configuration:'),
'#type' => 'textarea',
'#rows' => 24,
'#prefix' => '<div id="edit-export-wrapper">',
'#suffix' => '</div>',
];
if ($config_type && $config_name) {
$fake_form_state = (new FormState())->setValues([
'config_type' => $config_type,
'config_name' => $config_name,
]);
$form['export'] = $this->updateExport($form, $fake_form_state);
}
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.