Adds a new text_styles table keyed by field_key ("{table}.{slugOrId}.{column}")
so any individual text field anywhere in the dashboard can get its own
font-family/font-size/color override, without a dedicated column per field.
App\Support\TextStyleFields is a server-side registry of which table/column/
permission combinations are valid, so TextStyleController::update() can't be
used to write styling for a field outside the caller's own permission domain,
and typos can't create permanently orphaned rows. Resetting all three values
deletes the row entirely rather than leaving it null, so the table only ever
holds fields an admin actually customized.
Font-size reuses the same "curated list, mirrored PHP+JS constant" approach
already used for font-family (App\Support\Fonts / fontOptions.js) - a free px
input on dozens of independently-edited fields with no design review step is
the most likely way to end up with an accidentally 4px or 400px heading.
New reusable pieces: TextStyleWidget.jsx (a self-contained font/size/color
toolbar with a live preview, used next to any field by passing its
field_key) and TextStylesContext.jsx + useTextStyle() hook (bulk-fetches all
styles once per page load in PublicLayout.jsx, same pattern as
SiteSettingsContext). This first phase wires both into the home-section
eyebrow/title/button-label fields (the ones from the screenshot that started
this) as a proven pilot; the registry is designed so extending it to the
remaining ~15 admin pages is just adding entries and wiring the widget/hook,
no new architecture.
Verified locally via direct PHP invocation: migration creates the table,
registry validation accepts only known table/slug-or-id/column
combinations and rejects the rest, upsert/reset round-trips correctly, and
a second migration run doesn't re-touch anything.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
17 lines
806 B
SQL
17 lines
806 B
SQL
USE hifi_shop;
|
|
|
|
-- Generischer Stil (Schriftart/-groesse/Farbe) pro einzelnem Textfeld irgendwo im Dashboard,
|
|
-- statt eigener Spalten pro Tabelle/Feld. field_key identifiziert das Feld eindeutig (Format
|
|
-- "{tabelle}.{slugOderId}.{spalte}"), serverseitig validiert gegen TextStyleFields::TABLES.
|
|
-- Additiv, nichts wird geloescht.
|
|
-- Hinweis: Auf der Live-Seite reicht stattdessen ein Klick auf "Datenbankstruktur aktualisieren"
|
|
-- unter Admin-Panel -> Einstellungen -> Datenbank.
|
|
|
|
CREATE TABLE IF NOT EXISTS text_styles (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
field_key VARCHAR(190) NOT NULL UNIQUE,
|
|
font_family VARCHAR(255) NULL,
|
|
font_size VARCHAR(20) NULL,
|
|
color VARCHAR(20) NULL,
|
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
) ENGINE=InnoDB;
|