Führe einen gemeinsamen Layoutvertrag ein und integriere die Premium-Widgets.
Layoutvertrag (ADR-38) in der bestehenden Registry: Jede Widget-Art erklärt zulässige Rasterbreiten (supportedUnits), Höhen aus einem gemeinsamen Vokabular (heights, gespeichert als settings.height), Darstellungsmodi und Verhalten bei wenig Platz. Unzulässige Breiten werden beim Speichern verständlich abgewiesen; Höhe „fill“ streckt den Handlungsaufruf auf die Abschnittszeile. Premium-Widgets nach Brand-UI-Kit v1.6: - hero Version 2: photo_split/editorial_solid, Höhen compact/normal/ large, Label, Überschriftenebene, Akzent, Bildfokus in Prozent, zwei Schaltflächen; nur 3 oder 4 Einheiten. Upgrade aus Version 1. - image_text Version 3: Fläche cream/clear/navy, Höhen compact/normal/ spacious, Label, zwei Schaltflächen, Bildfokus; 1 bis 4 Einheiten. Upgrade aus Version 2 (format entfällt, Fokus in Prozent). - Kit-CSS ersetzt das bisherige Hero- und Bild-und-Text-CSS; der Randlos-Mechanismus der Designiteration 1 entfällt. Editor: Reiter Inhalt/Medien/Darstellung aus der Registry, Auswahl- knöpfe mit Symbolen, Schieberegler für den Bildfokus und eine Live- Vorschau im Dialog mit demselben Renderer in wählbarer Platzbreite. Tests bewusst angepasst: Einstieg braucht jetzt 3 oder 4 Einheiten (vorher Mindestbreite 2), image_text ist Version 3, Klassen der neuen Ansichten; die Hero-/Bild-Tests der Designiteration 1 sind durch CmsPremiumWidgetsTest ersetzt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3cdb36e7a3
commit
0bfb53463a
38 files changed
+1755
-856
No files matched your search
@@ -264,11 +264,11 @@ private function normalizeSection(array $section, int $index, array &$errors, ar
|
||||
}
|
||||
|
||||
$type = $this->widgets->get($widget['type']);
|
||||
if ($slotUnits < $type->minUnits()) {
|
||||
if (! $type->supportsUnits($slotUnits)) {
|
||||
$errors["$prefix.slots.$position.units"] = [sprintf(
|
||||
'„%s“ braucht mindestens %d Rastereinheiten; dieser Platz hat %d. Wählen Sie ein breiteres Raster oder einen breiteren Platz.',
|
||||
'„%s“ ist für Plätze mit %s Rastereinheiten vorgesehen; dieser Platz hat %d. Wählen Sie ein passendes Raster oder einen passenden Platz.',
|
||||
$type->label(),
|
||||
$type->minUnits(),
|
||||
$type->unitsLabel(),
|
||||
$slotUnits,
|
||||
)];
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
* - Ein Abschnitt ohne darstellbares Widget entfällt samt Hintergrund und Trenner.
|
||||
* - Das erste dargestellte Widget der Seite ist der Seiteneinstieg (Überschrift erster Ordnung).
|
||||
* - Trenner stehen zwischen Abschnitten, nie nach dem letzten.
|
||||
* - Steht ein randloses Widget (WidgetType::bleeds) allein im Abschnitt, entfallen Innenabstand und Breitenbegrenzung.
|
||||
*/
|
||||
class SectionRenderer
|
||||
{
|
||||
@@ -44,7 +43,7 @@ public function renderAll(array $sections, RenderContext $context): HtmlString
|
||||
|
||||
if ($html !== '') {
|
||||
$first = false;
|
||||
$cells[] = ['units' => $slotUnits, 'html' => $html, 'bleeds' => $this->widgets->bleeds($widget)];
|
||||
$cells[] = ['units' => $slotUnits, 'html' => $html];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +69,7 @@ public function renderAll(array $sections, RenderContext $context): HtmlString
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $section
|
||||
* @param list<array{units: int, html: string, bleeds: bool}> $cells
|
||||
* @param list<array{units: int, html: string}> $cells
|
||||
*/
|
||||
private function renderSection(array $section, array $cells, int $index): string
|
||||
{
|
||||
@@ -106,10 +105,6 @@ private function renderSection(array $section, array $cells, int $index): string
|
||||
$classes[] = 'section-divider-space';
|
||||
}
|
||||
|
||||
if (count($cells) === 1 && $cells[0]['bleeds']) {
|
||||
$classes[] = 'section-bleed';
|
||||
}
|
||||
|
||||
$id = is_string($section['id'] ?? null) ? ' id="bereich-'.e($section['id']).'"' : '';
|
||||
$html = '<div class="'.e(implode(' ', $classes)).'"'.$id.'>';
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Support;
|
||||
|
||||
use App\Domain\Cms\Sections\SectionStyle;
|
||||
|
||||
/**
|
||||
* Bildausschnitt für Widget-Bilder: dieselben Fokuspunkte wie beim Abschnittshintergrund (SectionStyle::FOCUS).
|
||||
* Der Fokus bestimmt den Zuschnitt, wenn ein Bild in ein festes Seitenverhältnis gesetzt wird.
|
||||
*/
|
||||
final class ImageFocus
|
||||
{
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function options(): array
|
||||
{
|
||||
return SectionStyle::FOCUS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $settings
|
||||
*/
|
||||
public static function position(array $settings, string $key = 'focus'): string
|
||||
{
|
||||
$focus = $settings[$key] ?? 'center';
|
||||
|
||||
return SectionStyle::FOCUS_POSITIONS[is_string($focus) && isset(SectionStyle::FOCUS_POSITIONS[$focus]) ? $focus : 'center'];
|
||||
}
|
||||
}
|
||||
@@ -16,18 +16,21 @@
|
||||
final class ImageRefFields
|
||||
{
|
||||
/**
|
||||
* @param bool $live Änderungen sofort an die Vorschau im Bearbeitungsdialog geben.
|
||||
* @return list<Field>
|
||||
*/
|
||||
public static function fields(string $label = 'Bild'): array
|
||||
public static function fields(string $label = 'Bild', bool $live = false): array
|
||||
{
|
||||
return [
|
||||
Select::make('image')
|
||||
->live($live)
|
||||
->label($label.': vorhandenes Bild')
|
||||
->options(fn (): array => PublicMedia::imageOptions())
|
||||
->searchable()
|
||||
->placeholder('Kein Bild')
|
||||
->helperText('Auswahl aus den Bildern, die bereits für die Website hochgeladen wurden.'),
|
||||
FileUpload::make('_upload')
|
||||
->live($live)
|
||||
->label($label.': neu hochladen')
|
||||
->disk('cms_incoming')
|
||||
->directory('cms')
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Support;
|
||||
|
||||
use App\Domain\Cms\Sections\SectionStyle;
|
||||
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||
use Filament\Forms\Components\Slider;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
|
||||
/**
|
||||
* Gemeinsame Bausteine der Premium-Widgets (Einstieg, Bild und Text; Brand-UI-Kit v1.6): Label, Überschriftenebene,
|
||||
* Bildfokus in Prozent und zwei Schaltflächen. Alle Werte bleiben in data bzw. settings der bestehenden Hülle.
|
||||
*
|
||||
* Abweichungen vom Kit (bewusst, dokumentiert in cms-widget-registry.md):
|
||||
* - Bildfokus als data.focus_x / data.focus_y (ganze Zahlen 0–100), weil settings nur Aufzählungswerte trägt.
|
||||
* - Überschriftenebene „Automatisch“ statt freier H1: Die Seite hat genau eine H1 (erstes Widget der Seite).
|
||||
* - Linkziele über SafeUrl des Repositorys (Seitenpfad, #Anker, http und https), nicht nur https.
|
||||
*/
|
||||
final class PremiumFields
|
||||
{
|
||||
public const HEADING_LEVELS = [
|
||||
'auto' => 'Automatisch (Seiteneinstieg H1, sonst H2)',
|
||||
'h2' => 'H2',
|
||||
'h3' => 'H3',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function rules(): array
|
||||
{
|
||||
return [
|
||||
'eyebrow' => ['nullable', 'string', 'max:80'],
|
||||
'cta_label' => ['nullable', 'string', 'max:80', 'required_with:data.cta_url'],
|
||||
'cta_url' => ['nullable', 'string', 'max:500', 'required_with:data.cta_label'],
|
||||
'cta2_label' => ['nullable', 'string', 'max:80', 'required_with:data.cta2_url'],
|
||||
'cta2_url' => ['nullable', 'string', 'max:500', 'required_with:data.cta2_label'],
|
||||
'alt' => ['nullable', 'string', 'max:300'],
|
||||
'focus_x' => ['nullable', 'numeric', 'between:0,100'],
|
||||
'focus_y' => ['nullable', 'numeric', 'between:0,100'],
|
||||
];
|
||||
}
|
||||
|
||||
public static function eyebrowField(): TextInput
|
||||
{
|
||||
return TextInput::make('eyebrow')
|
||||
->label('Label über der Überschrift (optional)')
|
||||
->maxLength(80)
|
||||
->live(onBlur: true)
|
||||
->helperText('Kurzer Hinweis, zum Beispiel ein Themenbereich. Kein Pflichtfeld.');
|
||||
}
|
||||
|
||||
public static function ctaFields(): Grid
|
||||
{
|
||||
$url = fn (string $name, string $label, string $pair) => TextInput::make($name)
|
||||
->label($label)
|
||||
->maxLength(500)
|
||||
->rule(SafeUrl::rule())
|
||||
->requiredWith($pair)
|
||||
->live(onBlur: true)
|
||||
->placeholder('/programme');
|
||||
|
||||
return Grid::make(['default' => 1, 'md' => 2])->schema([
|
||||
TextInput::make('cta_label')->label('Hauptschaltfläche: Beschriftung')->maxLength(80)->live(onBlur: true),
|
||||
$url('cta_url', 'Hauptschaltfläche: Linkziel', 'cta_label'),
|
||||
TextInput::make('cta2_label')->label('Zweite Schaltfläche: Beschriftung')->maxLength(80)->live(onBlur: true),
|
||||
$url('cta2_url', 'Zweite Schaltfläche: Linkziel', 'cta2_label'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<Slider>
|
||||
*/
|
||||
public static function focusFields(int $defaultX = 50, int $defaultY = 50): array
|
||||
{
|
||||
// Ohne gespeicherten Wert zeigt der Regler die Vorgabe der Widget-Art, die auch die Darstellung verwendet.
|
||||
$slider = fn (string $name, string $label, int $default) => Slider::make($name)
|
||||
->label($label)
|
||||
->range(0, 100)
|
||||
->step(1)
|
||||
->required(false)
|
||||
->tooltips()
|
||||
->default($default)
|
||||
->afterStateHydrated(function (Slider $component, mixed $state) use ($default): void {
|
||||
if (! is_numeric($state)) {
|
||||
$component->state($default);
|
||||
}
|
||||
})
|
||||
->live();
|
||||
|
||||
return [
|
||||
$slider('focus_x', 'Bildausschnitt waagerecht (0 = links, 100 = rechts)', $defaultX),
|
||||
$slider('focus_y', 'Bildausschnitt senkrecht (0 = oben, 100 = unten)', $defaultY),
|
||||
];
|
||||
}
|
||||
|
||||
public static function altField(): TextInput
|
||||
{
|
||||
return TextInput::make('alt')
|
||||
->label('Alternativtext des Bildes')
|
||||
->maxLength(300)
|
||||
->live(onBlur: true)
|
||||
->helperText('Beschreibt, was auf dem Bild zu sehen ist. Pflicht, sobald ein Bild gewählt ist.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Bereinigt Label, Schaltflächen, Alternativtext und Fokus; meldet unsichere Linkziele.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function clean(array $data, WidgetErrors $errors, bool $hasImage): array
|
||||
{
|
||||
foreach (['eyebrow', 'cta_label', 'cta_url', 'cta2_label', 'cta2_url', 'alt'] as $key) {
|
||||
$data[$key] = filled($data[$key] ?? null) ? trim((string) $data[$key]) : null;
|
||||
}
|
||||
|
||||
foreach (['cta_url', 'cta2_url'] as $key) {
|
||||
if ($data[$key] !== null && ! SafeUrl::isSafe($data[$key])) {
|
||||
$errors->add("data.$key", SafeUrl::message());
|
||||
}
|
||||
}
|
||||
|
||||
foreach (['focus_x', 'focus_y'] as $key) {
|
||||
$value = $data[$key] ?? null;
|
||||
$data[$key] = is_numeric($value) ? (int) round(max(0, min(100, (float) $value))) : null;
|
||||
}
|
||||
|
||||
if ($hasImage && $data['alt'] === null) {
|
||||
$errors->add('data.alt', 'Bitte einen Alternativtext für das Bild angeben.');
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schaltflächen mit sicherem Linkziel in Anzeigereihenfolge.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
* @return list<array{label: string, url: string}>
|
||||
*/
|
||||
public static function actions(array $data): array
|
||||
{
|
||||
$actions = [];
|
||||
|
||||
foreach ([['cta_label', 'cta_url'], ['cta2_label', 'cta2_url']] as [$label, $url]) {
|
||||
if (filled($data[$label] ?? null) && SafeUrl::isSafe($data[$url] ?? null)) {
|
||||
$actions[] = ['label' => (string) $data[$label], 'url' => (string) $data[$url]];
|
||||
}
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bildfokus in Prozent; ohne Angabe die Vorgabe der Widget-Art.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
* @return array{x: int, y: int}
|
||||
*/
|
||||
public static function focus(array $data, int $defaultX = 50, int $defaultY = 50): array
|
||||
{
|
||||
$clamp = fn (mixed $value, int $default): int => is_numeric($value) ? (int) round(max(0, min(100, (float) $value))) : $default;
|
||||
|
||||
return ['x' => $clamp($data['focus_x'] ?? null, $defaultX), 'y' => $clamp($data['focus_y'] ?? null, $defaultY)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Übersetzt den früheren Fokuspunkt (Aufzählung wie beim Abschnittshintergrund) in Prozentwerte.
|
||||
*
|
||||
* @return array{focus_x: int|null, focus_y: int|null}
|
||||
*/
|
||||
public static function focusFromEnum(mixed $focus): array
|
||||
{
|
||||
if (! is_string($focus) || ! isset(SectionStyle::FOCUS_POSITIONS[$focus])) {
|
||||
return ['focus_x' => null, 'focus_y' => null];
|
||||
}
|
||||
|
||||
[$x, $y] = array_map(fn (string $part): int => (int) rtrim($part, '%'), explode(' ', SectionStyle::FOCUS_POSITIONS[$focus]));
|
||||
|
||||
return ['focus_x' => $x, 'focus_y' => $y];
|
||||
}
|
||||
|
||||
/**
|
||||
* Überschriftenebene: „auto“ ergibt H1 für das erste Widget der Seite, sonst H2. Eine weitere H1 gibt es nicht.
|
||||
*
|
||||
* @param array<string, mixed> $settings
|
||||
*/
|
||||
public static function headingTag(array $settings, bool $first): string
|
||||
{
|
||||
$level = $settings['heading_level'] ?? 'auto';
|
||||
|
||||
return match (true) {
|
||||
$first => 'h1',
|
||||
$level === 'h3' => 'h3',
|
||||
default => 'h2',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -25,9 +25,22 @@ public function description(): string
|
||||
return 'Hervorgehobene Fläche mit Überschrift, Text und einer Schaltfläche.';
|
||||
}
|
||||
|
||||
public function minUnits(): int
|
||||
public function supportedUnits(): array
|
||||
{
|
||||
return 1;
|
||||
return [1, 2, 3, 4];
|
||||
}
|
||||
|
||||
public function narrowBehavior(): string
|
||||
{
|
||||
return 'Unter 20 rem Slotbreite steht die Schaltfläche in voller Breite; Überschrift, Text und Beschriftung brechen um.';
|
||||
}
|
||||
|
||||
public function heights(): array
|
||||
{
|
||||
return [
|
||||
'auto' => 'Automatisch (nach Inhalt)',
|
||||
'fill' => 'Abschnittshöhe füllen (gleich hoch wie Nachbarplätze)',
|
||||
];
|
||||
}
|
||||
|
||||
public function preferredUnits(): int
|
||||
|
||||
@@ -35,9 +35,14 @@ public function description(): string
|
||||
return 'Mehrere Karten mit Titel, Text, Linkziel und optionalem Bild. Als Raster, kompakte Liste oder mit hervorgehobener erster Karte.';
|
||||
}
|
||||
|
||||
public function minUnits(): int
|
||||
public function supportedUnits(): array
|
||||
{
|
||||
return 1;
|
||||
return [1, 2, 3, 4];
|
||||
}
|
||||
|
||||
public function narrowBehavior(): string
|
||||
{
|
||||
return 'Karten stehen untereinander, sobald keine zwei 15 rem breiten Karten nebeneinander passen; die hervorgehobene Karte stapelt Bild und Text.';
|
||||
}
|
||||
|
||||
public function preferredUnits(): int
|
||||
|
||||
@@ -37,9 +37,14 @@ public function description(): string
|
||||
return 'Ausgewählte Programme und Module; Titel und Beschreibung kommen automatisch aus den Fachdaten.';
|
||||
}
|
||||
|
||||
public function minUnits(): int
|
||||
public function supportedUnits(): array
|
||||
{
|
||||
return 1;
|
||||
return [1, 2, 3, 4];
|
||||
}
|
||||
|
||||
public function narrowBehavior(): string
|
||||
{
|
||||
return 'Karten stehen untereinander, die Markentafel über dem Text; lange Titel brechen um.';
|
||||
}
|
||||
|
||||
public function preferredUnits(): int
|
||||
|
||||
@@ -24,9 +24,14 @@ public function description(): string
|
||||
return 'Häufige Fragen mit Antworten.';
|
||||
}
|
||||
|
||||
public function minUnits(): int
|
||||
public function supportedUnits(): array
|
||||
{
|
||||
return 2;
|
||||
return [2, 3, 4];
|
||||
}
|
||||
|
||||
public function narrowBehavior(): string
|
||||
{
|
||||
return 'Fragen und Antworten untereinander; Antworten höchstens in Lesebreite.';
|
||||
}
|
||||
|
||||
public function preferredUnits(): int
|
||||
|
||||
@@ -23,9 +23,14 @@ public function description(): string
|
||||
return 'Abschnittsüberschrift mit kurzem Einleitungstext.';
|
||||
}
|
||||
|
||||
public function minUnits(): int
|
||||
public function supportedUnits(): array
|
||||
{
|
||||
return 1;
|
||||
return [1, 2, 3, 4];
|
||||
}
|
||||
|
||||
public function narrowBehavior(): string
|
||||
{
|
||||
return 'Überschriftengröße folgt der Platzbreite; lange Wörter werden getrennt.';
|
||||
}
|
||||
|
||||
public function preferredUnits(): int
|
||||
|
||||
@@ -3,17 +3,23 @@
|
||||
namespace App\Domain\Cms\Widgets\Types;
|
||||
|
||||
use App\Domain\Cms\Widgets\RenderContext;
|
||||
use App\Domain\Cms\Widgets\Support\ImageFocus;
|
||||
use App\Domain\Cms\Widgets\Support\ImageRefFields;
|
||||
use App\Domain\Cms\Widgets\Support\PremiumFields;
|
||||
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
||||
use App\Domain\Cms\Widgets\Support\SafeUrl;
|
||||
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||
use App\Domain\Cms\Widgets\WidgetType;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Components\Group;
|
||||
|
||||
/**
|
||||
* Premium-Einstieg nach Brand-UI-Kit v1.6 (12_premium_widgets_adaptiv_v1.6, Komponente lf-hero).
|
||||
*
|
||||
* Version 2: Varianten photo_split und editorial_solid, Höhen compact/normal/large (Mindesthöhen ab 860 px
|
||||
* Containerbreite), Label, Überschriftenebene, Bildfokus in Prozent, Akzent, zwei Schaltflächen.
|
||||
* Die data-Schlüssel der Version 1 (heading, text, cta_*, alt) bleiben unverändert, damit ältere Revisionen und ein
|
||||
* Code-Rollback darstellbar bleiben.
|
||||
*/
|
||||
class HeroWidget extends WidgetType
|
||||
{
|
||||
public function key(): string
|
||||
@@ -28,27 +34,46 @@ public function label(): string
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Großer Seiteneinstieg mit Überschrift, Beschreibung, optionalem Bild und bis zu zwei Schaltflächen. Als Markenbühne randlos über die volle Breite.';
|
||||
return 'Markenprägender Seiteneinstieg: großes Foto mit Textfläche oder dunkle Markenfläche, Überschrift, Beschreibung und bis zu zwei Schaltflächen.';
|
||||
}
|
||||
|
||||
public function minUnits(): int
|
||||
public function version(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function preferredUnits(): int
|
||||
public function supportedUnits(): array
|
||||
{
|
||||
return 4;
|
||||
return [3, 4];
|
||||
}
|
||||
|
||||
public function stages(): array
|
||||
{
|
||||
return [
|
||||
'narrow' => 'unter 48rem Slotbreite: Bild über beziehungsweise unter dem Text',
|
||||
'wide' => 'ab 48rem: Bild neben dem Text, größere Überschrift; Markenbühne ab 56rem mit Text auf dem Bild',
|
||||
'wide' => 'ab 860 px Containerbreite: Foto über die ganze Fläche, Text links auf heller Fläche; Mindesthöhe nach Höheneinstellung',
|
||||
'safety' => 'unter 860 px nur technischer Sicherheitsumbruch: Foto 16:9 über dem Text, Schaltflächen ab 440 px untereinander',
|
||||
];
|
||||
}
|
||||
|
||||
public function narrowBehavior(): string
|
||||
{
|
||||
return 'Für breite Plätze (3 oder 4 Einheiten). Unter 860 px Containerbreite steht das Foto über dem Text; die Höhe richtet sich dann nach dem Inhalt.';
|
||||
}
|
||||
|
||||
public function heights(): array
|
||||
{
|
||||
return [
|
||||
'compact' => 'Kompakt (mind. 400 px)',
|
||||
'normal' => 'Normal (mind. 512 px)',
|
||||
'large' => 'Groß (mind. 640 px)',
|
||||
];
|
||||
}
|
||||
|
||||
public function defaultHeight(): ?string
|
||||
{
|
||||
return 'normal';
|
||||
}
|
||||
|
||||
public function icon(): string
|
||||
{
|
||||
return 'heroicon-o-sparkles';
|
||||
@@ -56,38 +81,64 @@ public function icon(): string
|
||||
|
||||
public function schematic(): array
|
||||
{
|
||||
return [[2, 3, 56, 30, 'line'], [6, 8, 26, 6, 'ink'], [6, 17, 24, 3, 'line'], [6, 24, 12, 5, 'accent'], [36, 7, 18, 22, 'image']];
|
||||
return [[2, 3, 56, 30, 'image'], [6, 8, 24, 6, 'ink'], [6, 16, 10, 2, 'accent'], [6, 21, 22, 3, 'line'], [6, 27, 12, 4, 'accent']];
|
||||
}
|
||||
|
||||
public function variants(): array
|
||||
{
|
||||
return [
|
||||
'standard' => 'Standard (Bild neben dem Text)',
|
||||
'highlight' => 'Hervorgehoben (Markenfläche)',
|
||||
'stage' => 'Markenbühne (großes Bild, randlos)',
|
||||
'editorial' => 'Editorial (textbetont)',
|
||||
'photo_split' => 'Foto mit Textfläche',
|
||||
'editorial_solid' => 'Markenfläche (ohne Foto)',
|
||||
];
|
||||
}
|
||||
|
||||
public function optionIcons(): array
|
||||
{
|
||||
return [
|
||||
'variant' => ['photo_split' => 'heroicon-o-photo', 'editorial_solid' => 'heroicon-o-swatch'],
|
||||
'height' => ['compact' => 'heroicon-o-bars-2', 'normal' => 'heroicon-o-bars-3', 'large' => 'heroicon-o-bars-4'],
|
||||
];
|
||||
}
|
||||
|
||||
public function settings(): array
|
||||
{
|
||||
return [
|
||||
'focus' => ImageFocus::options(),
|
||||
'text_side' => ['left' => 'Links', 'right' => 'Rechts'],
|
||||
'heading_level' => PremiumFields::HEADING_LEVELS,
|
||||
'accent' => ['underline' => 'Gelbe Unterstreichung', 'rays' => 'Unterstreichung und Signalstrahlen', 'none' => 'Ohne Akzent'],
|
||||
];
|
||||
}
|
||||
|
||||
public function settingLabels(): array
|
||||
{
|
||||
return [
|
||||
'focus' => ['Bildausschnitt', 'Welcher Bildteil bei engen Zuschnitten sichtbar bleibt.'],
|
||||
'text_side' => ['Textseite (Markenbühne)', 'Auf welcher Seite der Text über dem Bild steht. Vorgabe: rechts.'],
|
||||
'heading_level' => ['Überschriftenebene', 'Der erste Einstieg einer Seite ist immer die Hauptüberschrift (H1).'],
|
||||
'accent' => ['Markenakzent', 'Freigegebene Akzente aus dem Brand-UI-Kit. Vorgabe: gelbe Unterstreichung.'],
|
||||
];
|
||||
}
|
||||
|
||||
public function bleeds(array $widget): bool
|
||||
/**
|
||||
* Version 1 (bis Designiteration 1) → 2: Varianten abbilden, früheren Fokuspunkt in Prozent umrechnen,
|
||||
* nicht mehr vorhandene Einstellungen (focus, text_side) entfernen. Inhalte bleiben unverändert.
|
||||
*/
|
||||
public function upgrade(array $widget, int $from): array
|
||||
{
|
||||
return ($widget['variant'] ?? null) === 'stage' && PublicMedia::isPublicPath($widget['refs']['image'] ?? null);
|
||||
if ($from !== 1) {
|
||||
return parent::upgrade($widget, $from);
|
||||
}
|
||||
|
||||
$widget['variant'] = in_array($widget['variant'] ?? null, ['highlight', 'editorial'], true) ? 'editorial_solid' : 'photo_split';
|
||||
$settings = is_array($widget['settings'] ?? null) ? $widget['settings'] : [];
|
||||
$data = is_array($widget['data'] ?? null) ? $widget['data'] : [];
|
||||
|
||||
if (! isset($data['focus_x'], $data['focus_y'])) {
|
||||
$data = PremiumFields::focusFromEnum($settings['focus'] ?? null) + $data;
|
||||
}
|
||||
|
||||
unset($settings['focus'], $settings['text_side']);
|
||||
$widget['settings'] = $settings;
|
||||
$widget['data'] = $data;
|
||||
|
||||
return $widget;
|
||||
}
|
||||
|
||||
public function dataRules(): array
|
||||
@@ -95,12 +146,7 @@ public function dataRules(): array
|
||||
return [
|
||||
'heading' => ['required', 'string', 'max:200'],
|
||||
'text' => ['nullable', 'string', 'max:600'],
|
||||
'cta_label' => ['nullable', 'string', 'max:80', 'required_with:data.cta_url'],
|
||||
'cta_url' => ['nullable', 'string', 'max:500', 'required_with:data.cta_label'],
|
||||
'cta2_label' => ['nullable', 'string', 'max:80', 'required_with:data.cta2_url'],
|
||||
'cta2_url' => ['nullable', 'string', 'max:500', 'required_with:data.cta2_label'],
|
||||
'alt' => ['nullable', 'string', 'max:300'],
|
||||
];
|
||||
] + PremiumFields::rules();
|
||||
}
|
||||
|
||||
public function refRules(): array
|
||||
@@ -111,85 +157,57 @@ public function refRules(): array
|
||||
public function dataFields(): array
|
||||
{
|
||||
return [
|
||||
TextInput::make('heading')->label('Überschrift')->required()->maxLength(200),
|
||||
Textarea::make('text')->label('Beschreibung')->rows(3)->maxLength(600),
|
||||
Grid::make(2)->schema([
|
||||
TextInput::make('cta_label')->label('Schaltfläche: Beschriftung (optional)')->maxLength(80),
|
||||
TextInput::make('cta_url')
|
||||
->label('Schaltfläche: Linkziel')
|
||||
->maxLength(500)
|
||||
->rule(SafeUrl::rule())
|
||||
->requiredWith('cta_label'),
|
||||
]),
|
||||
Grid::make(2)->schema([
|
||||
TextInput::make('cta2_label')->label('Zweite Schaltfläche: Beschriftung (optional)')->maxLength(80),
|
||||
TextInput::make('cta2_url')
|
||||
->label('Zweite Schaltfläche: Linkziel')
|
||||
->maxLength(500)
|
||||
->rule(SafeUrl::rule())
|
||||
->requiredWith('cta2_label'),
|
||||
]),
|
||||
TextInput::make('alt')
|
||||
->label('Alternativtext des Bildes')
|
||||
->maxLength(300)
|
||||
->helperText('Pflicht, sobald ein Bild gewählt ist.'),
|
||||
PremiumFields::eyebrowField(),
|
||||
TextInput::make('heading')->label('Überschrift')->required()->maxLength(200)->live(onBlur: true),
|
||||
Textarea::make('text')->label('Beschreibung')->rows(3)->maxLength(600)->live(onBlur: true),
|
||||
PremiumFields::ctaFields(),
|
||||
PremiumFields::altField(),
|
||||
...PremiumFields::focusFields(68, 50),
|
||||
];
|
||||
}
|
||||
|
||||
public function refFields(): array
|
||||
{
|
||||
return ImageRefFields::fields();
|
||||
return ImageRefFields::fields(live: true);
|
||||
}
|
||||
|
||||
public function editorSchema(): array
|
||||
{
|
||||
[$heading, $text, $cta, $cta2, $alt] = $this->dataFields();
|
||||
[$eyebrow, $heading, $text, $ctas] = $this->dataFields();
|
||||
|
||||
return [Group::make([$eyebrow, $heading, $text, $ctas])->statePath('data')];
|
||||
}
|
||||
|
||||
public function mediaSchema(): array
|
||||
{
|
||||
[, , , , $alt, $focusX, $focusY] = $this->dataFields();
|
||||
|
||||
return [
|
||||
Group::make([$heading, $text, $cta, $cta2])->statePath('data'),
|
||||
Group::make($this->refFields())->statePath('refs'),
|
||||
Group::make([$alt])->statePath('data'),
|
||||
Group::make([$alt, $focusX, $focusY])->statePath('data'),
|
||||
];
|
||||
}
|
||||
|
||||
public function clean(array $data, array $refs, WidgetErrors $errors): array
|
||||
{
|
||||
$refs = ImageRefFields::clean($refs, $errors);
|
||||
|
||||
foreach (['text', 'cta_label', 'cta_url', 'cta2_label', 'cta2_url', 'alt'] as $key) {
|
||||
$data[$key] = filled($data[$key] ?? null) ? trim($data[$key]) : null;
|
||||
}
|
||||
|
||||
foreach (['cta_url', 'cta2_url'] as $key) {
|
||||
if ($data[$key] !== null && ! SafeUrl::isSafe($data[$key])) {
|
||||
$errors->add("data.$key", SafeUrl::message());
|
||||
}
|
||||
}
|
||||
|
||||
if ($refs['image'] !== null && $data['alt'] === null) {
|
||||
$errors->add('data.alt', 'Bitte einen Alternativtext für das Bild angeben.');
|
||||
}
|
||||
$data['heading'] = trim((string) ($data['heading'] ?? ''));
|
||||
$data['text'] = filled($data['text'] ?? null) ? trim((string) $data['text']) : null;
|
||||
$data = PremiumFields::clean($data, $errors, $refs['image'] !== null);
|
||||
|
||||
return [$data, $refs];
|
||||
}
|
||||
|
||||
public function resolve(array $widget, RenderContext $context): array
|
||||
{
|
||||
$data = $widget['data'];
|
||||
$actions = [];
|
||||
|
||||
foreach ([['cta_label', 'cta_url'], ['cta2_label', 'cta2_url']] as [$label, $url]) {
|
||||
if (filled($data[$label] ?? null) && SafeUrl::isSafe($data[$url] ?? null)) {
|
||||
$actions[] = ['label' => $data[$label], 'url' => $data[$url]];
|
||||
}
|
||||
}
|
||||
$actions = PremiumFields::actions($widget['data']);
|
||||
|
||||
return [
|
||||
'imageUrl' => PublicMedia::imageUrl($widget['refs']),
|
||||
'action' => $actions[0] ?? null,
|
||||
'actions' => $actions,
|
||||
'focus' => ImageFocus::position($widget['settings'] ?? []),
|
||||
'textSide' => ($widget['settings']['text_side'] ?? null) === 'left' ? 'left' : 'right',
|
||||
'action' => $actions[0] ?? null,
|
||||
'focus' => PremiumFields::focus($widget['data'], 68, 50),
|
||||
'accent' => in_array($widget['settings']['accent'] ?? null, ['underline', 'rays', 'none'], true) ? $widget['settings']['accent'] : 'underline',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace App\Domain\Cms\Widgets\Types;
|
||||
|
||||
use App\Domain\Cms\Widgets\RenderContext;
|
||||
use App\Domain\Cms\Widgets\Support\ImageFocus;
|
||||
use App\Domain\Cms\Widgets\Support\ImageRefFields;
|
||||
use App\Domain\Cms\Widgets\Support\PremiumFields;
|
||||
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
||||
use App\Domain\Cms\Widgets\Support\RichText;
|
||||
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||
@@ -14,10 +14,13 @@
|
||||
use Filament\Schemas\Components\Group;
|
||||
|
||||
/**
|
||||
* Bild und Text.
|
||||
* Bild und Text, Premium-Fassung nach Brand-UI-Kit v1.6 (Komponente lf-bild-text).
|
||||
*
|
||||
* Version 1 (Bestand): data {image, alt, body} mit Klartext.
|
||||
* Version 2: data {title, body (formatierter Text), alt}, refs {image}, Varianten Bild links/rechts.
|
||||
* Version 3: zusätzlich Label, zwei Schaltflächen, Bildfokus in Prozent; Einstellungen Oberfläche, Höhe und
|
||||
* Überschriftenebene. Die Bildseite bleibt die Variante (keine doppelte Einstellung). Die Einstellung
|
||||
* format der Designiteration 1 entfällt; die Bildproportion folgt jetzt der Höhe.
|
||||
*/
|
||||
class ImageTextWidget extends WidgetType
|
||||
{
|
||||
@@ -33,12 +36,17 @@ public function label(): string
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Bild neben formatiertem Text; Bild links oder rechts, auf dem Smartphone untereinander.';
|
||||
return 'Redaktionelle Bild-Text-Komposition mit Label, formatiertem Text und bis zu zwei Schaltflächen; passt sich der Platzbreite an.';
|
||||
}
|
||||
|
||||
public function minUnits(): int
|
||||
public function version(): int
|
||||
{
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function supportedUnits(): array
|
||||
{
|
||||
return [1, 2, 3, 4];
|
||||
}
|
||||
|
||||
public function preferredUnits(): int
|
||||
@@ -49,14 +57,29 @@ public function preferredUnits(): int
|
||||
public function stages(): array
|
||||
{
|
||||
return [
|
||||
'narrow' => 'unter 36rem Slotbreite: Bild über dem Text',
|
||||
'wide' => 'ab 36rem: Bild links oder rechts neben dem Text, gleich breit; ab 56rem Bild betont (7:5)',
|
||||
'stacked' => 'unter 540 px Containerbreite: Bild über dem Text, Schaltflächen untereinander in voller Breite',
|
||||
'band' => '540 bis 899 px: flacher Bildstreifen über dem vollständigen Text (typisch zwei Einheiten)',
|
||||
'wide' => 'ab 900 px: Bild und Text nebeneinander, Bild links oder rechts nach Variante',
|
||||
];
|
||||
}
|
||||
|
||||
public function version(): int
|
||||
public function narrowBehavior(): string
|
||||
{
|
||||
return 2;
|
||||
return 'Unter 900 px Containerbreite steht das Bild über dem Text, unabhängig von „Bild links/rechts“; die gespeicherte Seite bleibt erhalten. Text und Schaltflächen werden nie gekürzt.';
|
||||
}
|
||||
|
||||
public function heights(): array
|
||||
{
|
||||
return [
|
||||
'compact' => 'Kompakt (flacheres Bild, engere Abstände)',
|
||||
'normal' => 'Normal',
|
||||
'spacious' => 'Großzügig (höheres Bild, mehr Abstand)',
|
||||
];
|
||||
}
|
||||
|
||||
public function defaultHeight(): ?string
|
||||
{
|
||||
return 'normal';
|
||||
}
|
||||
|
||||
public function icon(): string
|
||||
@@ -66,7 +89,7 @@ public function icon(): string
|
||||
|
||||
public function schematic(): array
|
||||
{
|
||||
return [[4, 6, 22, 24, 'image'], [30, 7, 24, 4, 'ink'], [30, 15, 26, 3, 'line'], [30, 21, 22, 3, 'line']];
|
||||
return [[4, 6, 22, 24, 'image'], [30, 7, 10, 2, 'accent'], [30, 11, 24, 4, 'ink'], [30, 18, 26, 3, 'line'], [30, 24, 14, 4, 'accent']];
|
||||
}
|
||||
|
||||
public function variants(): array
|
||||
@@ -77,40 +100,64 @@ public function variants(): array
|
||||
];
|
||||
}
|
||||
|
||||
public function optionIcons(): array
|
||||
{
|
||||
return [
|
||||
'variant' => ['image_left' => 'heroicon-o-arrow-left', 'image_right' => 'heroicon-o-arrow-right'],
|
||||
'height' => ['compact' => 'heroicon-o-bars-2', 'normal' => 'heroicon-o-bars-3', 'spacious' => 'heroicon-o-bars-4'],
|
||||
];
|
||||
}
|
||||
|
||||
public function settings(): array
|
||||
{
|
||||
return [
|
||||
'format' => ['landscape' => 'Querformat (4:3)', 'portrait' => 'Hochformat (4:5)', 'square' => 'Quadrat', 'original' => 'Originalformat'],
|
||||
'focus' => ImageFocus::options(),
|
||||
'surface' => ['cream' => 'Creme (Markenfläche)', 'clear' => 'Ohne eigene Fläche', 'navy' => 'Navy (dunkel)'],
|
||||
'heading_level' => PremiumFields::HEADING_LEVELS,
|
||||
];
|
||||
}
|
||||
|
||||
public function settingLabels(): array
|
||||
{
|
||||
return [
|
||||
'format' => ['Bildformat', 'Zuschnitt des Bildes. Vorgabe: Querformat.'],
|
||||
'focus' => ['Bildausschnitt', 'Welcher Bildteil beim Zuschnitt sichtbar bleibt.'],
|
||||
'surface' => ['Hintergrund des Widgets', 'Unabhängig vom Abschnittshintergrund. „Ohne eigene Fläche“ übernimmt den Abschnitt.'],
|
||||
'heading_level' => ['Überschriftenebene', 'Steht das Widget als erstes auf der Seite, ist die Überschrift immer H1.'],
|
||||
];
|
||||
}
|
||||
|
||||
public function upgrade(array $widget, int $from): array
|
||||
{
|
||||
if ($from !== 1) {
|
||||
return parent::upgrade($widget, $from);
|
||||
if ($from === 1) {
|
||||
$data = $widget['data'];
|
||||
|
||||
$widget['data'] = [
|
||||
'title' => null,
|
||||
'body' => RichText::fromPlainText(is_string($data['body'] ?? null) ? $data['body'] : ''),
|
||||
'alt' => $data['alt'] ?? null,
|
||||
];
|
||||
$widget['refs'] = [
|
||||
'image' => PublicMedia::fromUploadState($data['image'] ?? null),
|
||||
];
|
||||
|
||||
return $widget;
|
||||
}
|
||||
|
||||
$data = $widget['data'];
|
||||
if ($from === 2) {
|
||||
// Designiteration 1 → Premium: Fokus in Prozent, Bildformat entfällt (Proportion folgt der Höhe).
|
||||
$settings = is_array($widget['settings'] ?? null) ? $widget['settings'] : [];
|
||||
$data = is_array($widget['data'] ?? null) ? $widget['data'] : [];
|
||||
|
||||
$widget['data'] = [
|
||||
'title' => null,
|
||||
'body' => RichText::fromPlainText(is_string($data['body'] ?? null) ? $data['body'] : ''),
|
||||
'alt' => $data['alt'] ?? null,
|
||||
];
|
||||
$widget['refs'] = [
|
||||
'image' => PublicMedia::fromUploadState($data['image'] ?? null),
|
||||
];
|
||||
if (! isset($data['focus_x'], $data['focus_y'])) {
|
||||
$data = PremiumFields::focusFromEnum($settings['focus'] ?? null) + $data;
|
||||
}
|
||||
|
||||
return $widget;
|
||||
unset($settings['focus'], $settings['format']);
|
||||
$widget['settings'] = $settings;
|
||||
$widget['data'] = $data;
|
||||
|
||||
return $widget;
|
||||
}
|
||||
|
||||
return parent::upgrade($widget, $from);
|
||||
}
|
||||
|
||||
public function dataRules(): array
|
||||
@@ -118,8 +165,7 @@ public function dataRules(): array
|
||||
return [
|
||||
'title' => ['nullable', 'string', 'max:160'],
|
||||
'body' => ['required', 'string', 'max:40000'],
|
||||
'alt' => ['nullable', 'string', 'max:300'],
|
||||
];
|
||||
] + PremiumFields::rules();
|
||||
}
|
||||
|
||||
public function refRules(): array
|
||||
@@ -130,31 +176,38 @@ public function refRules(): array
|
||||
public function dataFields(): array
|
||||
{
|
||||
return [
|
||||
TextInput::make('title')->label('Titel (optional)')->maxLength(160),
|
||||
PremiumFields::eyebrowField(),
|
||||
TextInput::make('title')->label('Überschrift')->maxLength(160)->live(onBlur: true),
|
||||
RichEditor::make('body')
|
||||
->label('Text')
|
||||
->required()
|
||||
->live(onBlur: true)
|
||||
->toolbarButtons(RichText::TOOLBAR),
|
||||
TextInput::make('alt')
|
||||
->label('Alternativtext des Bildes')
|
||||
->maxLength(300)
|
||||
->helperText('Beschreibt, was auf dem Bild zu sehen ist. Pflicht, sobald ein Bild gewählt ist.'),
|
||||
PremiumFields::ctaFields(),
|
||||
PremiumFields::altField(),
|
||||
...PremiumFields::focusFields(64, 43),
|
||||
];
|
||||
}
|
||||
|
||||
public function refFields(): array
|
||||
{
|
||||
return ImageRefFields::fields();
|
||||
return ImageRefFields::fields(live: true);
|
||||
}
|
||||
|
||||
public function editorSchema(): array
|
||||
{
|
||||
[$title, $body, $alt] = $this->dataFields();
|
||||
[$eyebrow, $title, $body, $ctas] = $this->dataFields();
|
||||
|
||||
return [Group::make([$eyebrow, $title, $body, $ctas])->statePath('data')];
|
||||
}
|
||||
|
||||
public function mediaSchema(): array
|
||||
{
|
||||
[, , , , $alt, $focusX, $focusY] = $this->dataFields();
|
||||
|
||||
return [
|
||||
Group::make([$title, $body])->statePath('data'),
|
||||
Group::make($this->refFields())->statePath('refs'),
|
||||
Group::make([$alt])->statePath('data'),
|
||||
Group::make([$alt, $focusX, $focusY])->statePath('data'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -162,29 +215,26 @@ public function clean(array $data, array $refs, WidgetErrors $errors): array
|
||||
{
|
||||
$refs = ImageRefFields::clean($refs, $errors);
|
||||
$data['body'] = RichText::sanitize($data['body'] ?? '');
|
||||
$data['title'] = filled($data['title'] ?? null) ? trim($data['title']) : null;
|
||||
$data['alt'] = filled($data['alt'] ?? null) ? trim($data['alt']) : null;
|
||||
$data['title'] = filled($data['title'] ?? null) ? trim((string) $data['title']) : null;
|
||||
$data = PremiumFields::clean($data, $errors, $refs['image'] !== null);
|
||||
|
||||
if (RichText::isBlank($data['body'])) {
|
||||
$errors->add('data.body', 'Bitte einen Text eingeben.');
|
||||
}
|
||||
|
||||
if ($refs['image'] !== null && $data['alt'] === null) {
|
||||
$errors->add('data.alt', 'Bitte einen Alternativtext für das Bild angeben.');
|
||||
}
|
||||
|
||||
return [$data, $refs];
|
||||
}
|
||||
|
||||
public function resolve(array $widget, RenderContext $context): array
|
||||
{
|
||||
$format = $widget['settings']['format'] ?? 'landscape';
|
||||
$surface = $widget['settings']['surface'] ?? 'cream';
|
||||
|
||||
return [
|
||||
'imageUrl' => PublicMedia::imageUrl($widget['refs']),
|
||||
'body' => RichText::sanitize(is_string($widget['data']['body'] ?? null) ? $widget['data']['body'] : ''),
|
||||
'format' => in_array($format, ['landscape', 'portrait', 'square', 'original'], true) ? $format : 'landscape',
|
||||
'focus' => ImageFocus::position($widget['settings'] ?? []),
|
||||
'actions' => PremiumFields::actions($widget['data']),
|
||||
'focus' => PremiumFields::focus($widget['data'], 64, 43),
|
||||
'surface' => in_array($surface, ['cream', 'clear', 'navy'], true) ? $surface : 'cream',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,14 @@ public function description(): string
|
||||
return 'Längerer Text in Absätzen. Eine Leerzeile beginnt einen neuen Absatz.';
|
||||
}
|
||||
|
||||
public function minUnits(): int
|
||||
public function supportedUnits(): array
|
||||
{
|
||||
return 1;
|
||||
return [1, 2, 3, 4];
|
||||
}
|
||||
|
||||
public function narrowBehavior(): string
|
||||
{
|
||||
return 'Fließtext bricht um; Zeilen höchstens etwa 70 Zeichen.';
|
||||
}
|
||||
|
||||
public function preferredUnits(): int
|
||||
|
||||
@@ -45,8 +45,18 @@ public function register(WidgetType $type): void
|
||||
throw new InvalidArgumentException("Widget „{$key}“ braucht eine Schemaversion ab 1.");
|
||||
}
|
||||
|
||||
if ($type->minUnits() < 1 || $type->minUnits() > 4 || $type->preferredUnits() < $type->minUnits() || $type->preferredUnits() > 4) {
|
||||
throw new InvalidArgumentException("Widget „{$key}“ braucht eine Mindest- und Vorzugsbreite zwischen 1 und 4 Rastereinheiten.");
|
||||
// Gemeinsamer Layoutvertrag (ADR-38): Breiten, Vorzugsbreite und Höhen aus festen Wertebereichen.
|
||||
$units = $type->supportedUnits();
|
||||
if ($units === [] || array_diff($units, [1, 2, 3, 4]) !== [] || $units !== array_values(array_unique($units)) || ! $type->supportsUnits($type->preferredUnits())) {
|
||||
throw new InvalidArgumentException("Widget „{$key}“ braucht unterstützte Breiten zwischen 1 und 4 Rastereinheiten und eine darin enthaltene Vorzugsbreite.");
|
||||
}
|
||||
|
||||
if (array_diff(array_keys($type->heights()), array_keys(WidgetType::HEIGHTS)) !== []) {
|
||||
throw new InvalidArgumentException("Widget „{$key}“ verwendet eine Höhe außerhalb des gemeinsamen Vokabulars.");
|
||||
}
|
||||
|
||||
if (array_key_exists('height', $type->settings())) {
|
||||
throw new InvalidArgumentException("Widget „{$key}“ deklariert die Höhe über heights(), nicht über settings().");
|
||||
}
|
||||
|
||||
if ($type->variants() === []) {
|
||||
@@ -266,7 +276,7 @@ private function validateOne(WidgetType $type, array $widget, string $errorPrefi
|
||||
}
|
||||
|
||||
$settings = [];
|
||||
$allowedSettings = $type->settings();
|
||||
$allowedSettings = $type->settingOptions();
|
||||
foreach ($widget['settings'] as $key => $value) {
|
||||
if ($value === null || $value === '') {
|
||||
continue;
|
||||
|
||||
@@ -46,16 +46,6 @@ public function renderAll(?array $blocks, RenderContext $context): HtmlString
|
||||
return new HtmlString($html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ob die Instanz randlos dargestellt werden darf (siehe WidgetType::bleeds).
|
||||
*
|
||||
* @param array<string, mixed> $widget aktuelle Hülle
|
||||
*/
|
||||
public function bleeds(array $widget): bool
|
||||
{
|
||||
return $this->registry->has((string) ($widget['type'] ?? '')) && $this->registry->get($widget['type'])->bleeds($widget);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert eine Instanz samt Abschnittshülle. Liefert '' wenn das Widget nichts darzustellen hat.
|
||||
*
|
||||
@@ -71,6 +61,7 @@ public function renderWidget(array $widget, RenderContext $context, bool $first
|
||||
'refs' => $widget['refs'],
|
||||
'variant' => $widget['variant'],
|
||||
'settings' => $widget['settings'],
|
||||
'height' => $type->height($widget),
|
||||
'first' => $first,
|
||||
'context' => $context,
|
||||
] + $type->resolve($widget, $context))->render());
|
||||
@@ -81,7 +72,11 @@ public function renderWidget(array $widget, RenderContext $context, bool $first
|
||||
|
||||
$id = is_string($widget['id'] ?? null) ? ' id="abschnitt-'.e($widget['id']).'"' : '';
|
||||
|
||||
return '<section class="block widget widget-'.e(str_replace('_', '-', $widget['type'])).' widget-variant-'.e(str_replace('_', '-', $widget['variant'])).'"'.$id.'>'
|
||||
// Gemeinsamer Layoutvertrag (ADR-38): Höhe als Klasse an der Hülle, nur wenn die Art Höhen anbietet.
|
||||
$height = $type->height($widget);
|
||||
$heightClass = $height !== null ? ' widget-height-'.e($height) : '';
|
||||
|
||||
return '<section class="block widget widget-'.e(str_replace('_', '-', $widget['type'])).' widget-variant-'.e(str_replace('_', '-', $widget['variant'])).$heightClass.'"'.$id.'>'
|
||||
.$inner
|
||||
.'</section>';
|
||||
}
|
||||
|
||||
@@ -35,12 +35,57 @@ public function version(): int
|
||||
}
|
||||
|
||||
/**
|
||||
* Kleinste Slotbreite in logischen Rastereinheiten (1 bis 4), in der das Widget auf dem Desktop lesbar bleibt.
|
||||
* Ein schmalerer Slot wird beim Speichern abgewiesen. Auf Tablet und Smartphone stapeln die Slots ohnehin.
|
||||
* Gemeinsames Höhenvokabular aller Widget-Arten (ADR-38). Eine Art bietet davon nur die sinnvollen Werte an
|
||||
* (heights()). Die Höhe ist ein Gestaltungsparameter, nie eine Begrenzung: Inhalte erhalten immer den nötigen Platz.
|
||||
*/
|
||||
public const HEIGHTS = [
|
||||
'auto' => 'Automatisch',
|
||||
'compact' => 'Kompakt',
|
||||
'normal' => 'Normal',
|
||||
'large' => 'Groß',
|
||||
'spacious' => 'Großzügig',
|
||||
'fill' => 'Abschnittshöhe füllen',
|
||||
];
|
||||
|
||||
/**
|
||||
* Gemeinsamer Layoutvertrag (ADR-38), Teil 1: zulässige Platzbreiten in logischen Rastereinheiten (1 bis 4).
|
||||
* Ein Platz mit nicht unterstützter Breite wird beim Speichern abgewiesen. Auf Tablet und Smartphone stapeln die
|
||||
* Plätze; dort bestimmt die tatsächliche Containerbreite die Darstellung (Container-Abfragen), nicht die Einheitenzahl.
|
||||
*
|
||||
* @return list<int>
|
||||
*/
|
||||
public function supportedUnits(): array
|
||||
{
|
||||
return [1, 2, 3, 4];
|
||||
}
|
||||
|
||||
public function supportsUnits(int $units): bool
|
||||
{
|
||||
return in_array($units, $this->supportedUnits(), true);
|
||||
}
|
||||
|
||||
/** Kleinste zulässige Platzbreite; abgeleitet aus supportedUnits(). */
|
||||
public function minUnits(): int
|
||||
{
|
||||
return 1;
|
||||
return min($this->supportedUnits());
|
||||
}
|
||||
|
||||
/** Lesbare Angabe der zulässigen Platzbreiten, zum Beispiel „1 bis 4“ oder „3 oder 4“. */
|
||||
public function unitsLabel(): string
|
||||
{
|
||||
$units = $this->supportedUnits();
|
||||
|
||||
if (count($units) === 1) {
|
||||
return (string) $units[0];
|
||||
}
|
||||
|
||||
if ($units === range(min($units), max($units)) && count($units) > 2) {
|
||||
return min($units).' bis '.max($units);
|
||||
}
|
||||
|
||||
$last = array_pop($units);
|
||||
|
||||
return implode(', ', $units).' oder '.$last;
|
||||
}
|
||||
|
||||
/** Empfohlene Slotbreite in Rastereinheiten; Hinweis in der Widget-Auswahl. */
|
||||
@@ -60,6 +105,42 @@ public function stages(): array
|
||||
return ['fluid' => 'passt sich fließend an jede Slotbreite an'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gemeinsamer Layoutvertrag, Teil 2: angebotene Höhen (Schlüssel aus HEIGHTS => Bezeichnung im Editor).
|
||||
* Leer: keine Höhenwahl, die Höhe folgt dem Inhalt. Der erste Eintrag ist die Vorgabe.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function heights(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function defaultHeight(): ?string
|
||||
{
|
||||
$key = array_key_first($this->heights());
|
||||
|
||||
return $key === null ? null : (string) $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wirksame Höhe einer Instanz (gespeicherte Einstellung oder Vorgabe).
|
||||
*
|
||||
* @param array<string, mixed> $widget
|
||||
*/
|
||||
public function height(array $widget): ?string
|
||||
{
|
||||
$height = $widget['settings']['height'] ?? null;
|
||||
|
||||
return is_string($height) && array_key_exists($height, $this->heights()) ? $height : $this->defaultHeight();
|
||||
}
|
||||
|
||||
/** Gemeinsamer Layoutvertrag, Teil 3: Verhalten bei reduziertem Platzangebot (Hinweis im Editor und in der Dokumentation). */
|
||||
public function narrowBehavior(): string
|
||||
{
|
||||
return 'Text bricht um, nichts wird abgeschnitten.';
|
||||
}
|
||||
|
||||
/** Heroicon-Name für Auswahl und Liste im Editor. */
|
||||
public function icon(): string
|
||||
{
|
||||
@@ -114,14 +195,30 @@ public function settingLabels(): array
|
||||
}
|
||||
|
||||
/**
|
||||
* Ob die Instanz randlos über die volle Fensterbreite dargestellt wird, wenn sie allein in einem Abschnitt
|
||||
* mit Raster „4“ steht (zum Beispiel die Markenbühne). Der Abschnitt verzichtet dann auf Innenabstand und Begrenzung.
|
||||
* Alle zulässigen Einstellungen einschließlich der gemeinsamen Höhe. Registry-Prüfung, Editor und Darstellung
|
||||
* verwenden ausschließlich diese Zusammenführung.
|
||||
*
|
||||
* @param array<string, mixed> $widget
|
||||
* @return array<string, array<string, string>>
|
||||
*/
|
||||
public function bleeds(array $widget): bool
|
||||
final public function settingOptions(): array
|
||||
{
|
||||
return false;
|
||||
$options = $this->settings();
|
||||
|
||||
if ($this->heights() !== []) {
|
||||
$options['height'] = $this->heights();
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Symbole für die visuelle Auswahl im Editor: 'variant' oder Einstellungsschlüssel => [Wert => Heroicon].
|
||||
*
|
||||
* @return array<string, array<string, string>>
|
||||
*/
|
||||
public function optionIcons(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,6 +261,17 @@ public function refFields(): array
|
||||
*
|
||||
* @return list<Component>
|
||||
*/
|
||||
/**
|
||||
* Felder der Gruppe „Medien“ im Bearbeitungsdialog (Bild, Bildausschnitt, Alternativtext). Leer: keine eigene Gruppe;
|
||||
* Verweise stehen dann mit im Inhalt (editorSchema()).
|
||||
*
|
||||
* @return list<Component>
|
||||
*/
|
||||
public function mediaSchema(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function editorSchema(): array
|
||||
{
|
||||
$schema = [];
|
||||
|
||||
@@ -524,8 +524,8 @@ private static function slotLabel(array $state, ?int $index, mixed $layout): str
|
||||
$type = $items !== [] ? (array_values($items)[0]['type'] ?? null) : null;
|
||||
$registry = app(WidgetRegistry::class);
|
||||
|
||||
if ($registry->has($type) && $registry->get($type)->minUnits() > $slotUnits) {
|
||||
$label .= ' · zu schmal: „'.$registry->get($type)->label().'“ braucht '.$registry->get($type)->minUnits();
|
||||
if ($registry->has($type) && ! $registry->get($type)->supportsUnits($slotUnits)) {
|
||||
$label .= ' · passt nicht: „'.$registry->get($type)->label().'“ ist für '.$registry->get($type)->unitsLabel().' Einheiten vorgesehen';
|
||||
}
|
||||
|
||||
return $label;
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Tabs;
|
||||
use Filament\Schemas\Components\Tabs\Tab;
|
||||
use Filament\Schemas\Components\Text;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Components\View;
|
||||
use Illuminate\Foundation\Vite;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -83,34 +89,69 @@ public static function slotBuilder(string $name = 'widget'): Builder
|
||||
|
||||
public static function block(WidgetType $type): Block
|
||||
{
|
||||
$variants = $type->variants();
|
||||
$icons = $type->optionIcons();
|
||||
$display = [];
|
||||
|
||||
$schema = [Hidden::make('id')];
|
||||
|
||||
$schema[] = count($variants) > 1
|
||||
? ToggleButtons::make('variant')
|
||||
if (count($type->variants()) > 1) {
|
||||
$display[] = ToggleButtons::make('variant')
|
||||
->label('Darstellung')
|
||||
->options($variants)
|
||||
->options($type->variants())
|
||||
->icons($icons['variant'] ?? [])
|
||||
->default($type->defaultVariant())
|
||||
->inline()
|
||||
->required()
|
||||
: Hidden::make('variant')->default($type->defaultVariant());
|
||||
->live();
|
||||
}
|
||||
|
||||
if ($type->settings() !== []) {
|
||||
$settings = [];
|
||||
$labels = $type->settingLabels();
|
||||
foreach ($type->settings() as $key => $options) {
|
||||
$settings[] = Select::make($key)
|
||||
$settings = [];
|
||||
$labels = $type->settingLabels();
|
||||
foreach ($type->settingOptions() as $key => $options) {
|
||||
// Gemeinsame Höhe (ADR-38): immer als sichtbare Auswahl mit Vorgabe, nie als freie Eingabe.
|
||||
$settings[] = $key === 'height'
|
||||
? ToggleButtons::make('height')
|
||||
->label('Höhe')
|
||||
->helperText('Gestaltungsparameter, keine Begrenzung: Längere Inhalte erhalten immer den nötigen Platz.')
|
||||
->options($options)
|
||||
->icons($icons['height'] ?? [])
|
||||
->default($type->defaultHeight())
|
||||
->inline()
|
||||
->live()
|
||||
: Select::make($key)
|
||||
->label($labels[$key][0] ?? Str::headline($key))
|
||||
->helperText($labels[$key][1] ?? null)
|
||||
->placeholder('Vorgabe der Darstellung')
|
||||
->options($options);
|
||||
}
|
||||
$schema[] = Grid::make(['default' => 1, 'md' => min(3, count($settings))])->schema($settings)->statePath('settings');
|
||||
->options($options)
|
||||
->live();
|
||||
}
|
||||
|
||||
foreach ($type->editorSchema() as $component) {
|
||||
$schema[] = $component;
|
||||
if ($settings !== []) {
|
||||
$display[] = Grid::make(['default' => 1, 'md' => 2])->schema($settings)->statePath('settings');
|
||||
}
|
||||
|
||||
$variantField = count($type->variants()) > 1 ? [] : [Hidden::make('variant')->default($type->defaultVariant())];
|
||||
$content = $type->editorSchema();
|
||||
$media = $type->mediaSchema();
|
||||
|
||||
if ($display === [] && $media === []) {
|
||||
$schema = [Hidden::make('id'), ...$variantField, ...$content];
|
||||
} else {
|
||||
$tabs = [Tab::make('Inhalt')->icon('heroicon-o-pencil-square')->schema($content)];
|
||||
if ($media !== []) {
|
||||
$tabs[] = Tab::make('Medien')->icon('heroicon-o-photo')->schema($media);
|
||||
}
|
||||
if ($display !== []) {
|
||||
$tabs[] = Tab::make('Darstellung')->icon('heroicon-o-adjustments-horizontal')->schema([
|
||||
...$display,
|
||||
Text::make('Platzbreiten: '.$type->unitsLabel().' Rastereinheiten. '.$type->narrowBehavior()),
|
||||
]);
|
||||
}
|
||||
|
||||
$schema = [
|
||||
Hidden::make('id'),
|
||||
...$variantField,
|
||||
Tabs::make('Widget')->tabs($tabs)->contained(false),
|
||||
self::livePreview($type),
|
||||
];
|
||||
}
|
||||
|
||||
return WidgetBlock::make($type->key())
|
||||
@@ -238,6 +279,50 @@ public static function notifyErrors(array $errors, array $blocks): void
|
||||
->send();
|
||||
}
|
||||
|
||||
/** Logische Vorschaubreiten in px: tatsächliche Platzbreiten im Standardabschnitt bei 1440 px Fensterbreite. */
|
||||
public const PREVIEW_UNIT_WIDTHS = [1 => 310, 2 => 640, 3 => 960, 4 => 1300];
|
||||
|
||||
public const PREVIEW_PHONE_WIDTH = 390;
|
||||
|
||||
/**
|
||||
* Live-Vorschau im Bearbeitungsdialog: rendert den ungespeicherten Zustand mit derselben Ansicht wie die Website
|
||||
* in einer wählbaren Platzbreite. Die Breitenwahl (_preview_width) wird nicht gespeichert.
|
||||
*/
|
||||
private static function livePreview(WidgetType $type): Section
|
||||
{
|
||||
$default = (string) self::PREVIEW_UNIT_WIDTHS[$type->preferredUnits()];
|
||||
$widths = [(string) self::PREVIEW_PHONE_WIDTH => 'Smartphone'];
|
||||
foreach ($type->supportedUnits() as $units) {
|
||||
$widths[(string) self::PREVIEW_UNIT_WIDTHS[$units]] = $units.' '.($units === 1 ? 'Einheit' : 'Einheiten');
|
||||
}
|
||||
|
||||
return Section::make('Vorschau')
|
||||
->description('Änderungen erscheinen sofort. Unter 860 px zeigt der Einstieg den Sicherheitsumbruch, Bild und Text ab 900 px zwei Spalten.')
|
||||
->collapsible()
|
||||
->compact()
|
||||
->schema([
|
||||
ToggleButtons::make('_preview_width')
|
||||
->hiddenLabel()
|
||||
->options($widths)
|
||||
->default($default)
|
||||
->inline()
|
||||
->live()
|
||||
->dehydrated(false)
|
||||
->extraAttributes(['class' => 'luf-preview-width']),
|
||||
View::make('filament.cms.widget-live-preview')
|
||||
->viewData(fn (Get $get): array => [
|
||||
'html' => self::renderPreview($type->key(), [
|
||||
'variant' => $get('variant'),
|
||||
'settings' => $get('settings'),
|
||||
'data' => $get('data'),
|
||||
'refs' => $get('refs'),
|
||||
]),
|
||||
'stylesheets' => self::previewStylesheets(),
|
||||
'width' => (int) ($get('_preview_width') ?: $default),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blockvorschau: dieselbe Widget-Ansicht wie öffentlich, aus dem ungespeicherten Zustand.
|
||||
*
|
||||
@@ -292,9 +377,9 @@ private static function pickerLabel(WidgetType $type): HtmlString
|
||||
|
||||
private static function unitsHint(WidgetType $type): string
|
||||
{
|
||||
return $type->minUnits() === 1
|
||||
? 'Passt in jeden Platz'
|
||||
: 'Braucht einen Platz ab '.$type->minUnits().' Rastereinheiten';
|
||||
return $type->supportedUnits() === [1, 2, 3, 4]
|
||||
? 'Passt in jeden Platz (1 bis 4 Einheiten)'
|
||||
: 'Für Plätze mit '.$type->unitsLabel().' Rastereinheiten';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user