Ersetze die Symbolauswahl im CMS durch einen Wähler mit Raster, Gruppen und Suche

Das Feld steht in den Einstellungen aller Widgets und je Karte und Merkmal. Es trägt nur die Zeichnung des gewählten
Symbols; der Katalog mit allen Zeichnungen kommt beim Öffnen in einer Anfrage (nur Redaktion und Katalogverwaltung).
Mit Tastatur bedienbar. Dazu Katalog-Dokumentation, Tokens und Abnahme mit Screenshots (lokal geprüft, nicht auf luf-test).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-24 21:42:25 +01:00
1 parent edca8e864c
commit 1270e2e948
21 files changed
+409 -16

No files matched your search

+2 -5
View File
@@ -10,8 +10,8 @@
use App\Domain\Cms\Widgets\Support\WebsiteImage;
use App\Domain\Cms\Widgets\WidgetErrors;
use App\Domain\Cms\Widgets\WidgetType;
use App\Filament\Support\SymbolField;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Illuminate\Validation\Rule;
@@ -124,10 +124,7 @@ public function dataFields(): array
->label('Karten')
->schema([
TextInput::make('title')->label('Titel')->required()->maxLength(120),
Select::make('symbol')
->label('Symbol (optional)')
->options(HeadingAccent::symbols())
->placeholder('Kein Symbol')
SymbolField::make('symbol', 'Symbol (optional)')
->helperText('Kleine Grafik aus dem Brand-Kit über dem Titel. Größe und Ausrichtung im Reiter „Darstellung“.'),
Textarea::make('text')->label('Beschreibung')->rows(2)->maxLength(500),
TextInput::make('url')
@@ -7,8 +7,8 @@
use App\Domain\Cms\Widgets\Support\SafeUrl;
use App\Domain\Cms\Widgets\WidgetErrors;
use App\Domain\Cms\Widgets\WidgetType;
use App\Filament\Support\SymbolField;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Illuminate\Validation\Rule;
@@ -139,7 +139,7 @@ public function dataFields(): array
Repeater::make('items')
->label('Merkmale')
->schema([
Select::make('symbol')->label('Symbol')->options(HeadingAccent::symbols())->required(),
SymbolField::make('symbol', 'Symbol', required: true),
TextInput::make('title')->label('Kurztitel')->required()->maxLength(60),
Textarea::make('text')->label('Satz')->rows(2)->maxLength(200),
TextInput::make('url')
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App\Filament\Support;
use App\Support\Brand\SymbolCatalog;
use Filament\Forms\Components\ViewField;
use Illuminate\Validation\Rule;
/**
* Auswahlfeld für ein Symbol der Symbolbibliothek: Vorschau des gewählten Symbols und ein Raster zum Wählen (Gruppen,
* Suche, Tastatur) statt einer Auswahlliste. Katalog und Bilder lädt das Feld erst beim Öffnen (SymbolPickerController).
*
* Gespeichert wird nur der Schlüssel. Die Prüfung gegen den Katalog bleibt Sache des Widgets (ADR-30); das Feld prüft
* zusätzlich, damit ein manipulierter Wert gar nicht erst ankommt.
*/
final class SymbolField
{
public static function make(string $name = 'symbol', string $label = 'Symbol', bool $required = false): ViewField
{
return ViewField::make($name)
->label($label)
->view('filament.cms.symbol-feld')
->required($required)
->rule(Rule::in(array_keys(SymbolCatalog::options())));
}
}
+11 -7
View File
@@ -15,6 +15,7 @@
use Filament\Forms\Components\RichEditor\RichContentRenderer;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\ToggleButtons;
use Filament\Forms\Components\ViewField;
use Filament\Notifications\Notification;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Group;
@@ -125,7 +126,7 @@ public static function slotBuilder(string $name = 'widget'): Builder
/**
* Erklärung als kleines (i) neben der Bezeichnung: erscheint beim Überfahren und beim Fokussieren.
*/
private static function withInfo(ToggleButtons|Select $component, ?string $help): ToggleButtons|Select
private static function withInfo(ToggleButtons|Select|ViewField $component, ?string $help): ToggleButtons|Select|ViewField
{
return filled($help)
? $component->hintIcon('heroicon-m-information-circle', tooltip: $help)->hintColor('gray')
@@ -154,7 +155,7 @@ public static function block(WidgetType $type): Block
$labels = $type->settingLabels();
$hiddenWhen = $type->settingHiddenWhen();
$field = function (string $key) use ($options, $labels, $type, $icons, $hiddenWhen): Select|ToggleButtons {
$field = function (string $key) use ($options, $labels, $type, $icons, $hiddenWhen): Select|ToggleButtons|ViewField {
$help = $labels[$key][1] ?? null;
// Gemeinsame Höhe (ADR-38): immer als sichtbare Auswahl mit Vorgabe, nie als freie Eingabe.
$component = $key === 'height'
@@ -165,11 +166,14 @@ public static function block(WidgetType $type): Block
->default($type->defaultHeight())
->inline()
->live()
: Select::make($key)
->label($labels[$key][0] ?? Str::headline($key))
->placeholder('Vorgabe der Darstellung')
->options($options[$key])
->live();
: ($key === 'symbol'
// Symbole stehen in einem durchsuchbaren Raster (Symbolbibliothek), nicht in einer Auswahlliste.
? SymbolField::make('symbol', $labels[$key][0] ?? 'Symbol')->live()->columnSpanFull()
: Select::make($key)
->label($labels[$key][0] ?? Str::headline($key))
->placeholder('Vorgabe der Darstellung')
->options($options[$key])
->live());
if ($key === 'height') {
$help = 'Gestaltungsparameter, keine Begrenzung: Längere Inhalte erhalten immer den nötigen Platz.';
@@ -0,0 +1,43 @@
<?php
namespace App\Http\Controllers;
use App\Domain\Identity\StaffRole;
use App\Models\User;
use App\Support\Brand\SymbolCatalog;
use App\Support\Brand\Symbols;
use Illuminate\Http\JsonResponse;
/**
* Daten für den Symbolwähler im CMS (nur Redaktion und Katalogverwaltung): der Katalog als JSON, je Symbol mit seiner
* Zeichnung.
*
* Der Wähler lädt das erst beim Öffnen und einmal je Seitenaufruf. So stecken nicht 70 Zeichnungen in jeder Antwort
* des Formulars, und es braucht keine 70 einzelnen Bildabrufe.
*/
class SymbolPickerController extends Controller
{
public function catalog(): JsonResponse
{
$this->authorizeStaff();
// Eine Antwort mit allen Zeichnungen statt eines Bildes je Symbol: ein Aufruf, keine siebzig.
$groups = array_map(function (array $group): array {
$group['items'] = array_map(fn (array $item): array => $item + ['svg' => (string) Symbols::symbol($item['key'])], $group['items']);
return $group;
}, SymbolCatalog::groups());
return response()->json(['groups' => $groups])->header('Cache-Control', 'private, max-age=300');
}
private function authorizeStaff(): void
{
$user = auth('staff')->user();
abort_unless(
$user instanceof User && ($user->hasStaffRole(StaffRole::Redakteur) || $user->hasStaffRole(StaffRole::Katalogverwalter)),
403,
);
}
}