protected function ConfigInspectorItemForm::buildFormConfigElement in Configuration Inspector 8
Format config schema as a tree.
1 call to ConfigInspectorItemForm::buildFormConfigElement()
- ConfigInspectorItemForm::buildForm in src/
Form/ ConfigInspectorItemForm.php - Build configuration form with metadata and values.
File
- src/
Form/ ConfigInspectorItemForm.php, line 39
Class
- ConfigInspectorItemForm
- Defines a form for editing configuration translations.
Namespace
Drupal\config_inspector\FormCode
protected function buildFormConfigElement($schema, $collapsed = FALSE) {
$build = [];
foreach ($schema as $key => $element) {
$definition = $element
->getDataDefinition();
$label = $definition['label'] ?: $this
->t('N/A');
if ($element instanceof ArrayElement) {
$build[$key] = [
'#type' => 'details',
'#title' => $label,
'#open' => !$collapsed,
] + $this
->buildFormConfigElement($element, TRUE);
}
else {
$type = $definition['type'];
switch ($type) {
case 'boolean':
$type = 'checkbox';
break;
case 'string':
case 'color_hex':
case 'path':
case 'label':
$type = 'textfield';
break;
case 'text':
$type = 'textarea';
break;
case 'integer':
$type = 'number';
break;
}
$value = $element
->getString();
$build[$key] = [
'#type' => $type,
'#title' => $label,
'#default_value' => $value,
];
}
}
return $build;
}