Skip to content

[3.0] Name the variant a theme actually gave, instead of a blank option - #9446

Open
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/theme-option-labels
Open

[3.0] Name the variant a theme actually gave, instead of a blank option#9446
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/theme-option-labels

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Description

The theme options page (?action=admin;area=theme;sa=options;th=1) builds its variant and colour-mode drop-downs like this:

$available_variants[$variant] = Lang::getTxt('variant_' . $variant, file: 'Themes') ?? $variant;

The ?? $variant is there to cover a variant whose name the language files do not describe. It has never fired. Lang::getTxt() returns '' for a string it cannot find — it never returns null — so ?? passes the empty string straight through and the drop-down offers an option with no label.

A theme is free to name its variants anything, so this is the normal case rather than an edge one. With two variants installed, the list reads:

before after
variant list Default, "", "" Default, light, ocean

Same one-character change for colormode_*.

The second hunk is smaller and not user-visible: theme_opt_variant and theme_opt_colormode are asked for from Themes, but both strings live in Languages/en_US/Profile.php — which is where ThemeOptions.php:78 reads them from for the matching option on the user's own settings page. The labels do come out right today because the theme options page has already loaded Profile.php by the time these run, but Lang::loadFileForGetTxt() sees a key that came from an unexpected file and force-reloads to go looking for it. Naming the right file avoids that.

Verification

Neither branch is reachable on a stock 3.0 install — the default theme sets has_dark_mode = false and theme_variants = []. Both are reachable for any custom theme that ships variants, and both become reachable here when dark mode lands. To exercise it I temporarily set theme_variants = ['light', 'ocean'] and has_dark_mode = true in index.template.php and read the rendered <option> labels, before and after. That temporary edit is not part of this PR.

This is part of the effort to break #7933 into reviewable pieces — found while triaging the admin area, and separated out because it changes no template.

Issues References (Fixes|Related|Closes)

Related: #7933

The theme options page builds its variant and colour-mode drop-downs from
Lang::getTxt('variant_' . $variant) and getTxt('colormode_' . $mode), with
?? $variant behind each one to cover a name the language files do not
describe. That fallback has never fired: getTxt() returns '' for a string it
cannot find, never null, so ?? passes the empty string straight through and
the drop-down offers an entry with no label at all.

A theme may name its variants anything it likes, so this is the normal case
for any variant outside the handful the default files know about. With two
variants installed, the list read Default, "", "" - now it reads Default,
light, ocean.

While in here, theme_opt_variant and theme_opt_colormode are asked for from
Themes, but both live in Profile.php, which is where the matching option on
the user's own theme settings page reads them from. The labels do come out
right today, because the theme options page has already loaded Profile.php
by the time these run, but naming a file that does not hold the string makes
Lang::load() reload files to go looking for it.

Signed-off-by: Mathias Albert <mathiaspapealbert@hotmail.com>
Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants