public function ConfigSingleExportForm::buildForm in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/config/src/Form/ConfigSingleExportForm.php \Drupal\config\Form\ConfigSingleExportForm::buildForm()
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
- core/
modules/ config/ src/ Form/ ConfigSingleExportForm.php, line 78 - Contains \Drupal\config\Form\ConfigSingleExportForm.
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) {
foreach ($this->entityManager
->getDefinitions() as $entity_type => $definition) {
if ($definition
->isSubclassOf('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) {
$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 = array(
'system.simple' => $this
->t('Simple configuration'),
) + $entity_types;
$form['config_type'] = array(
'#title' => $this
->t('Configuration type'),
'#type' => 'select',
'#options' => $config_types,
'#default_value' => $config_type,
'#ajax' => array(
'callback' => '::updateConfigurationType',
'wrapper' => 'edit-config-type-wrapper',
),
);
$default_type = $form_state
->getValue('config_type', $config_type);
$form['config_name'] = array(
'#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' => array(
'callback' => '::updateExport',
'wrapper' => 'edit-export-wrapper',
),
);
$form['export'] = array(
'#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;
}