1 system.admin.inc | _system_format_debug_info(array $lines, array $format_settings) |
Given an array of data, it formats it into a plain-text 2-column output.
@private
@since 1.28.0 function added.
Parameters
array $lines: The data to format into plain text columns. Each line may contain keys for "label" and "value".
array $format_settings: An array with various settings that control the final plain-text output:
- min_spacing: An integer indicating the minimum spaces added between the first column of the output and the second column.
- rtl: A boolean indicating whether the output should be prepared for RTL languages.
See also
File
- core/
modules/ system/ system.admin.inc, line 2589 - Admin page callbacks for the System module.
Code
function _system_format_debug_info(array $lines, array $format_settings) {
global $language;
// Set some default settings.
$defaults = array(
'min_spacing' => 5,
'rtl' => $language->direction == LANGUAGE_RTL,
);
// Ensure that defaults are set for any settings that were not explicitly
// specified.
$format_settings += $defaults;
// Get the length of the longest key in the array (which will determine the
// max width of the first plain-text "column").
$longest_item_length = 0;
foreach ($lines as &$line_reference) {
$line_reference += array('label' => NULL, 'value' => NULL);
$label_length = backdrop_strlen($line_reference['label']);
if ($label_length > $longest_item_length) {
$longest_item_length = $label_length;
}
}
// Format the output so that the items and their values are listed as columns.
$first_col_width = $longest_item_length + $format_settings['min_spacing'];
$output = '';
foreach ($lines as $line) {
$label = $line['label'];
$value = $line['value'];
if ($label == NULL && $value == NULL) {
// Blank lines.
$output .= "\n";
}
else {
if ($format_settings['rtl']) {
$format = '%s %' . $first_col_width . 's';
// Note that the order of $value and $label parameters is reversed
// compared to LTR.
$output .= ltrim(sprintf($format, $value, $label)) . "\n";
}
else {
$format = '%-' . $first_col_width . 's %s';
$output .= rtrim(sprintf($format, $label, $value)) . "\n";
}
}
}
return $output;
}