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>
19 lines
557 B
PHP
19 lines
557 B
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use App\Config\Database;
|
|
|
|
/**
|
|
* Raeumt verwaiste text_styles-Zeilen auf, wenn die zugehoerige Entitaet geloescht wird (offene
|
|
* Tabellen wie faqs/services/brands - bei festen Tabellen wie home_sections/legal_pages gibt es
|
|
* keine Loeschfunktion, dort nicht noetig).
|
|
*/
|
|
class TextStyleCleanup
|
|
{
|
|
public static function forgetEntity(string $table, string $id): void
|
|
{
|
|
$stmt = Database::connection()->prepare('DELETE FROM text_styles WHERE field_key LIKE ?');
|
|
$stmt->execute(["$table.$id.%"]);
|
|
}
|
|
}
|