function ConfigSingleImportForm::buildForm
Same name in other branches
- 9 core/modules/config/src/Form/ConfigSingleImportForm.php \Drupal\config\Form\ConfigSingleImportForm::buildForm()
- 8.9.x core/modules/config/src/Form/ConfigSingleImportForm.php \Drupal\config\Form\ConfigSingleImportForm::buildForm()
- 10 core/modules/config/src/Form/ConfigSingleImportForm.php \Drupal\config\Form\ConfigSingleImportForm::buildForm()
Overrides ConfirmFormBase::buildForm
File
-
core/
modules/ config/ src/ Form/ ConfigSingleImportForm.php, line 161
Class
- ConfigSingleImportForm
- Provides a form for importing a single configuration file.
Namespace
Drupal\config\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// When this is the confirmation step fall through to the confirmation form.
if ($this->data) {
return parent::buildForm($form, $form_state);
}
$entity_types = [];
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type => $definition) {
if ($definition->entityClassImplements(ConfigEntityInterface::class)) {
$entity_types[$entity_type] = $definition->getLabel();
}
}
// 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,
'#required' => TRUE,
];
$form['config_name'] = [
'#title' => $this->t('Configuration name'),
'#description' => $this->t('Enter the name of the configuration file without the <em>.yml</em> extension. (e.g. <em>system.site</em>)'),
'#type' => 'textfield',
'#states' => [
'required' => [
':input[name="config_type"]' => [
'value' => 'system.simple',
],
],
'visible' => [
':input[name="config_type"]' => [
'value' => 'system.simple',
],
],
],
];
$form['import'] = [
'#title' => $this->t('Paste your configuration here'),
'#type' => 'textarea',
'#rows' => 24,
'#required' => TRUE,
];
$form['advanced'] = [
'#type' => 'details',
'#title' => $this->t('Advanced'),
];
$form['advanced']['custom_entity_id'] = [
'#title' => $this->t('Custom Entity ID'),
'#type' => 'textfield',
'#description' => $this->t('Specify a custom entity ID. This will override the entity ID in the configuration above.'),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Import'),
'#button_type' => 'primary',
];
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.