Skip to content

Commit

Permalink
rework font settings display
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoh committed Nov 22, 2023
1 parent fd3cbab commit 6afb450
Showing 1 changed file with 45 additions and 27 deletions.
72 changes: 45 additions & 27 deletions program/actions/settings/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -962,47 +962,65 @@ public static function user_prefs($current = null)
];
}

if (!isset($no_override['default_font']) || !isset($no_override['default_font_size'])) {
// Font settings are made up of 2 parts, font name and font size
// Compute the settings first to discover is anything to display to the user
$font_settings = '';

// Default font
if (!isset($no_override['default_font'])) {
if (!$current) {
continue 2;
}

// Default font size
$field_id = 'rcmfd_default_font_size';
$select_size = new html_select([
'name' => '_default_font_size',
'id' => $field_id,
'class' => 'custom-select'
]);
$fonts = self::font_defs();
if (count($fonts) > 1) {
$field_id = 'rcmfd_default_font';
$select_font = new html_select([
'name' => '_default_font',
'id' => $field_id,
'class' => 'custom-select'
]);

$select_size->add('', '');
$select_font->add('', '');

$fontsizes = self::fontsize_defs();
foreach ($fontsizes as $size) {
$select_size->add($size, $size);
foreach (array_keys($fonts) as $fname) {
$select_font->add($fname, $fname);
}

$font_settings .= $select_font->show($rcmail->config->get('default_font', 1));
}
}

// Default font
$field_id = 'rcmfd_default_font';
$select_font = new html_select([
'name' => '_default_font',
'id' => $field_id,
'class' => 'custom-select'
]);
// Default font size
if (!isset($no_override['default_font_size'])) {
if (!$current) {
continue 2;
}

$select_font->add('', '');
$fontsizes = self::fontsize_defs();
if (count($fontsizes) > 1) {
$field_id = 'rcmfd_default_font_size';
$select_size = new html_select([
'name' => '_default_font_size',
'id' => $field_id,
'class' => 'custom-select'
]);

$fonts = self::font_defs();
foreach (array_keys($fonts) as $fname) {
$select_font->add($fname, $fname);
$select_size->add('', '');

foreach ($fontsizes as $size) {
$select_size->add($size, $size);
}

$font_settings .= $select_size->show($rcmail->config->get('default_font_size', 1));
}
}

// Include font settings in the display only if at least one setting exists
if (!empty($font_settings)) {
$blocks['main']['options']['default_font'] = [
'title' => html::label($field_id, rcube::Q($rcmail->gettext('defaultfont'))),
'content' => html::div('input-group',
(!isset($no_override['default_font']) && count($fonts) > 1 ? $select_font->show($rcmail->config->get('default_font', 1)) : '') .
(!isset($no_override['default_font_size']) && count($fontsizes) > 1 ? $select_size->show($rcmail->config->get('default_font_size', 1)) : '')
)
'content' => html::div('input-group', $font_settings)
];
}

Expand Down

0 comments on commit 6afb450

Please sign in to comment.