public function ConfigInspectorController::formatTree in Configuration Inspector 8
Format config schema as a tree.
Parameters
array|object $schema: The schema.
bool $collapsed: (Optional) Indicates whether the details are collapsed by default.
string $base_key: Prefix used in the description.
Return value
array The tree in the form of a render array.
1 call to ConfigInspectorController::formatTree()
- ConfigInspectorController::getTree in src/
Controller/ ConfigInspectorController.php - Tree inspection view of the configuration.
File
- src/
Controller/ ConfigInspectorController.php, line 361
Class
- ConfigInspectorController
- Defines a controller for the config_inspector module.
Namespace
Drupal\config_inspector\ControllerCode
public function formatTree($schema, $collapsed = FALSE, $base_key = '') {
$build = [];
foreach ($schema as $key => $element) {
$definition = $element
->getDataDefinition();
$label = $definition['label'] ?: $this
->t('N/A');
$type = $definition['type'];
$element_key = $base_key . $key;
if ($element instanceof ArrayElement) {
$build[$key] = [
'#type' => 'details',
'#title' => $label,
'#description' => $element_key . ' (' . $type . ')',
'#description_display' => 'after',
'#open' => !$collapsed,
] + $this
->formatTree($element, TRUE, $element_key . '.');
}
else {
$build[$key] = [
'#type' => 'item',
'#title' => $label,
'#plain_text' => $this
->formatValue($element),
'#description' => $element_key . ' (' . $type . ')',
'#description_display' => 'after',
];
}
}
return $build;
}