Führe eine zentrale Widget-Registry mit visuellem Seiteneditor ein.
CI Feature / test (push) Successful in 31s
CI Feature / test (push) Successful in 31s
- Codebasiertes Widget-Register (config/cms.php) mit Vertrag
{id, type, v, variant, settings, data, refs}: Typkennung, Schemaversion,
Prüfregeln, freigegebene Varianten, Editorfelder, Blade-Ansicht,
Verweisauflösung und Medienliste je Widget-Art.
- Die sechs Bestandsbausteine bleiben als Version 1 lesbar; gespeicherte
Revisionen werden nicht umgeschrieben, sondern beim Lesen angehoben
(Bild und Text: Version 2 mit Titel, formatiertem Text, Bild links/rechts).
Wiederherstellen kopiert eine Revision unverändert.
- Neue Widgets: Einstieg (Hero) und Programm-/Modulkarten. Letztere speichern
nur Verweise; Titel und Kurzbeschreibung kommen aus den Fachdaten. Öffentlich
erscheinen nur Programme mit Anzeigefreigabe (gleiche Regel wie /programme,
jetzt in PublicCatalogReader); Module nur in der Redaktionsvorschau, bis
öffentliche Profile (ADR-29) bestehen.
- Ein Renderer für öffentliche Seite, Vorschau und Blockvorschau im Editor.
- Seiteneditor als Filament-Builder: Auswahl mit Beschreibung und Schema,
kompakte Abschnitte mit Vorschau, Bearbeitung im Dialog, Sortieren,
Duplizieren. Speichern erzeugt nur einen Entwurf.
- Vorschau einer Revision in 390/768/1440 px; Vorschauroute nutzt den
Personal-Guard (vorher war sie für Redakteure ohne Mitgliedersitzung
nicht erreichbar).
- Basislayout in Komponenten (Marke, Kopf, Fuß, Seitenvorlage).
- Navigation: bearbeiten, ausblenden, löschen, per Ziehen sortieren;
unsichere Adressen (javascript:) werden abgewiesen und nicht ausgegeben.
Ergänzende Migration is_visible (Vorgabe sichtbar).
- Pfadfehler und doppelte Pfade erscheinen am Pfadfeld statt still zu scheitern.
Tests: BlockRegistryTest geht in WidgetRegistryTest auf (gleiche Prüfungen
plus Registrierung, Versionierung, Bereinigung). Bestandsseiten werden gegen
Textfixtures aus dem Stand vor der Umstellung geprüft.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cfdd6de0c7
commit
9d936bfa4a
76 files changed
+4237
-475
No files matched your search
@@ -1,181 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Blocks;
|
||||
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class BlockRegistry
|
||||
{
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function labels(): array
|
||||
{
|
||||
return [
|
||||
'heading' => 'Überschrift und Einleitung',
|
||||
'prose' => 'Fließtext',
|
||||
'image_text' => 'Bild und Text',
|
||||
'call_to_action' => 'Handlungsaufruf',
|
||||
'cards' => 'Karten',
|
||||
'faq' => 'FAQ',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $blocks
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function normalize(array $blocks): array
|
||||
{
|
||||
$normalized = [];
|
||||
|
||||
foreach (array_values($blocks) as $index => $block) {
|
||||
if (! is_array($block)) {
|
||||
throw ValidationException::withMessages([
|
||||
"blocks.$index" => 'Ein Baustein ist unvollständig.',
|
||||
]);
|
||||
}
|
||||
|
||||
$type = $block['type'] ?? null;
|
||||
|
||||
if (! is_string($type) || ! array_key_exists($type, $this->labels())) {
|
||||
throw ValidationException::withMessages([
|
||||
"blocks.$index.type" => 'Dieser Bausteintyp ist nicht freigegeben.',
|
||||
]);
|
||||
}
|
||||
|
||||
$normalized[] = $this->normalizeOne($type, $block, $index);
|
||||
}
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $block
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function normalizeOne(string $type, array $block, int $index): array
|
||||
{
|
||||
$rules = match ($type) {
|
||||
'heading' => [
|
||||
'heading' => ['required', 'string', 'max:200'],
|
||||
'intro' => ['nullable', 'string', 'max:1000'],
|
||||
],
|
||||
'prose' => [
|
||||
'body' => ['required', 'string', 'max:20000'],
|
||||
],
|
||||
'image_text' => [
|
||||
'image' => ['nullable', 'string', 'max:255'],
|
||||
'alt' => ['required', 'string', 'max:300'],
|
||||
'body' => ['required', 'string', 'max:5000'],
|
||||
],
|
||||
'call_to_action' => [
|
||||
'heading' => ['required', 'string', 'max:200'],
|
||||
'text' => ['nullable', 'string', 'max:1000'],
|
||||
'label' => ['required', 'string', 'max:80'],
|
||||
'url' => ['required', 'string', 'max:500'],
|
||||
],
|
||||
'cards' => [
|
||||
'items' => ['required', 'array', 'min:1', 'max:6'],
|
||||
'items.*.title' => ['required', 'string', 'max:120'],
|
||||
'items.*.text' => ['nullable', 'string', 'max:500'],
|
||||
'items.*.url' => ['nullable', 'string', 'max:500'],
|
||||
],
|
||||
'faq' => [
|
||||
'items' => ['required', 'array', 'min:1', 'max:20'],
|
||||
'items.*.question' => ['required', 'string', 'max:300'],
|
||||
'items.*.answer' => ['required', 'string', 'max:2000'],
|
||||
],
|
||||
default => [],
|
||||
};
|
||||
|
||||
$validator = Validator::make($block, $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$messages = [];
|
||||
|
||||
foreach ($validator->errors()->messages() as $key => $errors) {
|
||||
$messages["blocks.$index.$key"] = $errors;
|
||||
}
|
||||
|
||||
throw ValidationException::withMessages($messages);
|
||||
}
|
||||
|
||||
$clean = ['type' => $type];
|
||||
|
||||
foreach (array_keys($rules) as $key) {
|
||||
if (str_contains($key, '.*')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$clean[$key] = $block[$key] ?? null;
|
||||
}
|
||||
|
||||
if ($type === 'image_text') {
|
||||
$clean['image'] = $this->imagePath($clean['image'] ?? null, $index);
|
||||
}
|
||||
|
||||
if (in_array($type, ['call_to_action', 'cards'], true)) {
|
||||
$clean = $this->assertSafeUrls($clean, $index);
|
||||
}
|
||||
|
||||
return $clean;
|
||||
}
|
||||
|
||||
private function imagePath(mixed $image, int $index): ?string
|
||||
{
|
||||
if (is_array($image)) {
|
||||
$image = $image[0] ?? null;
|
||||
}
|
||||
|
||||
if ($image === null || $image === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! is_string($image) || str_contains($image, '..') || ! str_starts_with($image, 'cms/')) {
|
||||
throw ValidationException::withMessages([
|
||||
"blocks.$index.image" => 'Das Bild liegt nicht im öffentlichen Medienbereich.',
|
||||
]);
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $block
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function assertSafeUrls(array $block, int $index): array
|
||||
{
|
||||
if (array_key_exists('url', $block)) {
|
||||
$block['url'] = $this->safeUrl($block['url'], "blocks.$index.url");
|
||||
}
|
||||
|
||||
if (isset($block['items']) && is_array($block['items'])) {
|
||||
foreach ($block['items'] as $itemIndex => $item) {
|
||||
if (is_array($item) && filled($item['url'] ?? null)) {
|
||||
$block['items'][$itemIndex]['url'] = $this->safeUrl($item['url'], "blocks.$index.items.$itemIndex.url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
||||
|
||||
private function safeUrl(mixed $url, string $key): string
|
||||
{
|
||||
if (! is_string($url)) {
|
||||
throw ValidationException::withMessages([$key => 'Die Adresse ist ungültig.']);
|
||||
}
|
||||
|
||||
$isRelative = str_starts_with($url, '/') && ! str_starts_with($url, '//');
|
||||
$isAbsolute = preg_match('#^https?://#i', $url) === 1;
|
||||
|
||||
if (! $isRelative && ! $isAbsolute) {
|
||||
throw ValidationException::withMessages([$key => 'Erlaubt sind Seitenpfade oder http(s)-Adressen.']);
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Catalog;
|
||||
|
||||
/**
|
||||
* Anzeigedaten eines Fachobjekts, zur Laufzeit aus den maßgeblichen Fachdaten gelesen. Wird nie gespeichert.
|
||||
*/
|
||||
final readonly class CatalogEntry
|
||||
{
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public string $title,
|
||||
public ?string $summary,
|
||||
public string $kindLabel,
|
||||
public ?string $url,
|
||||
public bool $public,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Catalog;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Catalog\CompositionDisplayRelease;
|
||||
use App\Domain\Catalog\CompositionVersion;
|
||||
use App\Domain\Catalog\EditorialContentKind;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Lesesicht „Öffentlicher Katalog“ für Website und CMS (Website-CMS-Zielarchitektur 5.1, 6.2).
|
||||
*
|
||||
* Übergangsregel, solange öffentliche Fachobjektprofile (ADR-29) fehlen:
|
||||
* Öffentlich gezeigt wird nur, was die Website bereits heute öffentlich zeigt, nämlich Kompositionen
|
||||
* der Inhaltsart „programm“ mit einer zur Anzeige freigegebenen Fassung (Route /programme).
|
||||
* Module haben noch keine öffentliche Seitenart; sie sind im Editor wählbar und erscheinen nur in
|
||||
* der geschützten Redaktionsvorschau, nie auf der öffentlichen Seite.
|
||||
*
|
||||
* Gelesen werden nur Anzeigetitel, Kurzbeschreibung und Inhaltsart, nie Dateien, Lehrtexte oder
|
||||
* Vorschaubilder der Bibliothek (diese sind geschützt, Paket 6).
|
||||
*/
|
||||
class PublicCatalogReader
|
||||
{
|
||||
/** Inhaltsarten mit öffentlicher Seitenart. */
|
||||
public const PUBLIC_KINDS = ['programm'];
|
||||
|
||||
/** Inhaltsarten, die ein Katalog-Widget referenzieren darf. */
|
||||
public const SELECTABLE_KINDS = ['programm', 'modul'];
|
||||
|
||||
public function __construct(private readonly CompositionDisplayRelease $releases) {}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Composition>
|
||||
*/
|
||||
public function publicPrograms(): Collection
|
||||
{
|
||||
$kind = EditorialContentKind::query()->where('slug', 'programm')->first();
|
||||
|
||||
if ($kind === null) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
return Composition::query()
|
||||
->where('editorial_content_kind_id', $kind->id)
|
||||
->orderBy('designation')
|
||||
->get()
|
||||
->filter(fn (Composition $composition): bool => $this->shownVersion($composition) !== null)
|
||||
->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gezeigte Fassung einer öffentlich gezeigten Komposition, sonst null.
|
||||
*/
|
||||
public function shownVersion(Composition $composition): ?CompositionVersion
|
||||
{
|
||||
if (! in_array($composition->editorialContentKind?->slug, self::PUBLIC_KINDS, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->releases->highestReleasedVersion($composition);
|
||||
}
|
||||
|
||||
public function isPublic(Composition $composition): bool
|
||||
{
|
||||
return $this->shownVersion($composition) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wählbar sind Programme und Module mit zur Anzeige freigegebener Fassung, die nicht archiviert sind.
|
||||
*/
|
||||
public function isSelectable(Composition $composition): bool
|
||||
{
|
||||
return $composition->archived_at === null
|
||||
&& in_array($composition->editorialContentKind?->slug, self::SELECTABLE_KINDS, true)
|
||||
&& $this->releases->highestReleasedVersion($composition) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Suchtreffer für die Auswahl im Editor: Kennung => Bezeichnung mit Sichtbarkeitshinweis.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function search(?string $term, int $limit = 25): array
|
||||
{
|
||||
$term = trim((string) $term);
|
||||
|
||||
$candidates = Composition::query()
|
||||
->with('editorialContentKind')
|
||||
->whereNull('archived_at')
|
||||
->whereHas('editorialContentKind', fn ($query) => $query->whereIn('slug', self::SELECTABLE_KINDS))
|
||||
->when($term !== '', function ($query) use ($term): void {
|
||||
$like = '%'.mb_strtolower($term).'%';
|
||||
$query->where(fn ($inner) => $inner
|
||||
->whereRaw('LOWER(designation) LIKE ?', [$like])
|
||||
->orWhereRaw('LOWER(COALESCE(display_title, \'\')) LIKE ?', [$like]));
|
||||
})
|
||||
->orderBy('designation')
|
||||
->limit($limit * 3)
|
||||
->get();
|
||||
|
||||
$options = [];
|
||||
|
||||
foreach ($candidates as $composition) {
|
||||
if (! $this->isSelectable($composition)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$options[$composition->id] = $this->optionLabel($composition);
|
||||
|
||||
if (count($options) >= $limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function labelFor(mixed $id): ?string
|
||||
{
|
||||
$composition = is_numeric($id) ? Composition::query()->with('editorialContentKind')->find((int) $id) : null;
|
||||
|
||||
return $composition === null ? null : $this->optionLabel($composition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Löst Verweise in Anzeigeeinträge auf. Öffentlich entfallen nicht öffentliche Objekte stillschweigend.
|
||||
*
|
||||
* @param list<array{type?: mixed, id?: mixed}> $refs
|
||||
* @return list<CatalogEntry>
|
||||
*/
|
||||
public function entries(array $refs, bool $includeNonPublic): array
|
||||
{
|
||||
$ids = [];
|
||||
foreach ($refs as $ref) {
|
||||
if (is_array($ref) && ($ref['type'] ?? null) === 'composition' && is_numeric($ref['id'] ?? null)) {
|
||||
$ids[] = (int) $ref['id'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($ids === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$compositions = Composition::query()->with('editorialContentKind')->whereIn('id', $ids)->get()->keyBy('id');
|
||||
$entries = [];
|
||||
|
||||
foreach (array_unique($ids) as $id) {
|
||||
$composition = $compositions->get($id);
|
||||
|
||||
if ($composition === null || ! $this->isSelectable($composition)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$public = $this->isPublic($composition);
|
||||
|
||||
if (! $public && ! $includeNonPublic) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$entries[] = new CatalogEntry(
|
||||
id: $composition->id,
|
||||
title: $this->title($composition),
|
||||
summary: filled($composition->summary) ? (string) $composition->summary : null,
|
||||
kindLabel: (string) ($composition->editorialContentKind?->label ?? ''),
|
||||
url: $public ? route('public.program', $composition) : null,
|
||||
public: $public,
|
||||
);
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
private function title(Composition $composition): string
|
||||
{
|
||||
return (string) ($composition->display_title ?: $composition->designation);
|
||||
}
|
||||
|
||||
private function optionLabel(Composition $composition): string
|
||||
{
|
||||
$visibility = $this->isPublic($composition) ? 'öffentlich sichtbar' : 'nur Redaktionsvorschau';
|
||||
|
||||
return $this->title($composition).' · '.($composition->editorialContentKind?->label ?? '').' · '.$visibility;
|
||||
}
|
||||
}
|
||||
@@ -2,35 +2,58 @@
|
||||
|
||||
namespace App\Domain\Cms;
|
||||
|
||||
use App\Domain\Cms\Widgets\Support\SafeUrl;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class NavigationItem extends Model
|
||||
{
|
||||
public const PLACEMENTS = [
|
||||
'header' => 'Kopfzeile',
|
||||
'footer' => 'Fußzeile',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'label',
|
||||
'page_id',
|
||||
'url',
|
||||
'placement',
|
||||
'sort_order',
|
||||
'is_visible',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_visible' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function page(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Page::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<NavigationItem> $query
|
||||
*/
|
||||
public function scopeVisible(Builder $query): void
|
||||
{
|
||||
$query->where('is_visible', true);
|
||||
}
|
||||
|
||||
public function href(): ?string
|
||||
{
|
||||
if ($this->page !== null) {
|
||||
return $this->page->path === '/' ? url('/') : url($this->page->path);
|
||||
}
|
||||
|
||||
if ($this->url === null || $this->url === '') {
|
||||
if ($this->url === null || $this->url === '' || ! SafeUrl::isSafe($this->url)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (str_starts_with($this->url, '/') && ! str_starts_with($this->url, '//')) {
|
||||
if (str_starts_with($this->url, '/')) {
|
||||
return url($this->url);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,17 +48,12 @@ public function publicUrl(): string
|
||||
public function publicTitle(): string
|
||||
{
|
||||
$revision = $this->publishedRevision;
|
||||
$heading = collect($revision?->blocks ?? [])->firstWhere('type', 'heading');
|
||||
|
||||
if (is_string($revision?->seo_title) && $revision->seo_title !== '') {
|
||||
return $revision->seo_title;
|
||||
}
|
||||
|
||||
if (is_array($heading) && is_string($heading['heading'] ?? null) && $heading['heading'] !== '') {
|
||||
return $heading['heading'];
|
||||
}
|
||||
|
||||
return $this->path;
|
||||
return $revision?->contentTitle() ?? $this->path;
|
||||
}
|
||||
|
||||
public function pillars(): BelongsToMany
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Domain\Cms;
|
||||
|
||||
use App\Domain\Cms\Widgets\WidgetRegistry;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -35,4 +36,22 @@ public function author(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* Bausteine als aktuelle Widget-Hüllen. Die gespeicherten Daten bleiben unverändert.
|
||||
*
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function widgets(): array
|
||||
{
|
||||
return app(WidgetRegistry::class)->read($this->blocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Titel aus dem ersten Überschriften- oder Einstiegs-Widget.
|
||||
*/
|
||||
public function contentTitle(): ?string
|
||||
{
|
||||
return app(WidgetRegistry::class)->pageTitle($this->blocks);
|
||||
}
|
||||
}
|
||||
@@ -2,36 +2,23 @@
|
||||
|
||||
namespace App\Domain\Cms;
|
||||
|
||||
use App\Domain\Cms\Blocks\BlockRegistry;
|
||||
use App\Domain\Cms\Widgets\WidgetRegistry;
|
||||
use App\Jobs\PublishPublicMedia;
|
||||
use App\Models\User;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class PageService
|
||||
{
|
||||
public function __construct(private readonly BlockRegistry $blocks) {}
|
||||
public function __construct(private readonly WidgetRegistry $widgets) {}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $blocks
|
||||
* Speichert einen Entwurf als neue Revision. Veröffentlicht nichts.
|
||||
*
|
||||
* @param array<int|string, mixed> $blocks Bausteine im Altformat oder als Widget-Hülle
|
||||
*/
|
||||
public function saveRevision(Page $page, array $blocks, ?string $seoTitle, ?string $seoDescription, ?User $author): PageRevision
|
||||
{
|
||||
$normalized = $this->blocks->normalize($blocks);
|
||||
|
||||
$revision = $page->revisions()->create([
|
||||
'blocks' => $normalized,
|
||||
'seo_title' => $seoTitle !== null && $seoTitle !== '' ? $seoTitle : null,
|
||||
'seo_description' => $seoDescription !== null && $seoDescription !== '' ? $seoDescription : null,
|
||||
'created_by' => $author?->id,
|
||||
]);
|
||||
|
||||
foreach ($normalized as $block) {
|
||||
if (($block['type'] ?? null) === 'image_text' && filled($block['image'] ?? null)) {
|
||||
PublishPublicMedia::dispatch($block['image']);
|
||||
}
|
||||
}
|
||||
|
||||
return $revision;
|
||||
return $this->storeRevision($page, $this->widgets->normalize($blocks), $seoTitle, $seoDescription, $author);
|
||||
}
|
||||
|
||||
public function publish(Page $page, PageRevision $revision): void
|
||||
@@ -46,6 +33,10 @@ public function publish(Page $page, PageRevision $revision): void
|
||||
$page->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Legt den Stand einer früheren Revision unverändert als neue Revision an. Die gespeicherten Bausteine
|
||||
* werden nicht umgeschrieben; ältere Formate werden erst beim Lesen angehoben.
|
||||
*/
|
||||
public function restore(Page $page, PageRevision $source, ?User $author): PageRevision
|
||||
{
|
||||
if ($source->page_id !== $page->id) {
|
||||
@@ -54,15 +45,36 @@ public function restore(Page $page, PageRevision $source, ?User $author): PageRe
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->saveRevision(
|
||||
return $this->storeRevision(
|
||||
$page,
|
||||
$source->blocks,
|
||||
$source->blocks ?? [],
|
||||
$source->seo_title,
|
||||
$source->seo_description,
|
||||
$author,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalisiert den Pfad und prüft, dass keine andere Seite ihn verwendet.
|
||||
*/
|
||||
public function availablePath(string $path, ?Page $except = null): string
|
||||
{
|
||||
$path = $this->normalizePath($path);
|
||||
|
||||
$taken = Page::query()
|
||||
->where('path', $path)
|
||||
->when($except !== null, fn ($query) => $query->whereKeyNot($except->getKey()))
|
||||
->exists();
|
||||
|
||||
if ($taken) {
|
||||
throw ValidationException::withMessages([
|
||||
'path' => 'Diesen Pfad verwendet bereits eine andere Seite.',
|
||||
]);
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function normalizePath(string $path): string
|
||||
{
|
||||
$path = '/'.trim($path, '/');
|
||||
@@ -81,4 +93,23 @@ public function normalizePath(string $path): string
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int|string, mixed> $blocks
|
||||
*/
|
||||
private function storeRevision(Page $page, array $blocks, ?string $seoTitle, ?string $seoDescription, ?User $author): PageRevision
|
||||
{
|
||||
$revision = $page->revisions()->create([
|
||||
'blocks' => array_values($blocks),
|
||||
'seo_title' => $seoTitle !== null && $seoTitle !== '' ? $seoTitle : null,
|
||||
'seo_description' => $seoDescription !== null && $seoDescription !== '' ? $seoDescription : null,
|
||||
'created_by' => $author?->id,
|
||||
]);
|
||||
|
||||
foreach ($this->widgets->mediaPaths($revision->blocks) as $path) {
|
||||
PublishPublicMedia::dispatch($path);
|
||||
}
|
||||
|
||||
return $revision;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms;
|
||||
|
||||
/**
|
||||
* Seitenvorlagen der öffentlichen Website. Eine Vorlage ordnet die gerenderten Widgets im Inhaltsbereich
|
||||
* des gemeinsamen Layouts an. Derzeit gibt es nur „standard“; weitere Vorlagen (zum Beispiel für
|
||||
* Themen- oder Landingpages) werden in config/cms.php ergänzt und später über einen Seitentyp gewählt.
|
||||
*/
|
||||
class PageTemplates
|
||||
{
|
||||
public const DEFAULT = 'standard';
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function all(): array
|
||||
{
|
||||
return config('cms.templates', [self::DEFAULT => 'site.templates.standard']);
|
||||
}
|
||||
|
||||
public function viewFor(Page $page): string
|
||||
{
|
||||
$templates = $this->all();
|
||||
|
||||
return $templates[self::DEFAULT];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets;
|
||||
|
||||
/**
|
||||
* Darstellungsrahmen. In der Vorschau zeigen Widgets zusätzlich redaktionelle Hinweise,
|
||||
* zum Beispiel auf Verweise, die öffentlich nicht erscheinen.
|
||||
*/
|
||||
final readonly class RenderContext
|
||||
{
|
||||
public function __construct(public bool $preview = false) {}
|
||||
|
||||
public static function publicPage(): self
|
||||
{
|
||||
return new self(preview: false);
|
||||
}
|
||||
|
||||
public static function preview(): self
|
||||
{
|
||||
return new self(preview: true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Support;
|
||||
|
||||
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||
use Filament\Forms\Components\Field;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
|
||||
/**
|
||||
* Gemeinsame Bildauswahl für Widgets: vorhandenes Bild aus dem öffentlichen Website-Bereich wählen
|
||||
* oder ein neues hochladen. Keine eigene Medienverwaltung.
|
||||
*/
|
||||
final class ImageRefFields
|
||||
{
|
||||
/**
|
||||
* @return list<Field>
|
||||
*/
|
||||
public static function fields(string $label = 'Bild'): array
|
||||
{
|
||||
return [
|
||||
Select::make('image')
|
||||
->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')
|
||||
->label($label.': neu hochladen')
|
||||
->disk('cms_incoming')
|
||||
->directory('cms')
|
||||
->image()
|
||||
->maxSize(8192)
|
||||
->acceptedFileTypes(['image/jpeg', 'image/png', 'image/webp'])
|
||||
->getUploadedFileNameForStorageUsing(fn (TemporaryUploadedFile $file): string => Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)).'-'.Str::lower(Str::random(6)).'.'.$file->guessExtension())
|
||||
->helperText('Ein neues Bild ersetzt die Auswahl oben. Es wird beim Speichern im öffentlichen Bereich der Website abgelegt.'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function rules(): array
|
||||
{
|
||||
return [
|
||||
'image' => ['nullable', 'string', 'max:255'],
|
||||
'_upload' => ['nullable'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Übernimmt einen neuen Upload als Bild und prüft, dass das Bild im öffentlichen Bereich liegt.
|
||||
*
|
||||
* @param array<string, mixed> $refs
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function clean(array $refs, WidgetErrors $errors, string $key = 'image', ?string $errorKey = null): array
|
||||
{
|
||||
$upload = PublicMedia::fromUploadState($refs['_upload'] ?? null);
|
||||
$image = $upload ?? PublicMedia::fromUploadState($refs[$key] ?? null);
|
||||
|
||||
if ($image !== null && ! PublicMedia::isPublicPath($image)) {
|
||||
$errors->add($errorKey ?? "refs.$key", 'Das Bild liegt nicht im öffentlichen Medienbereich.');
|
||||
}
|
||||
|
||||
$refs[$key] = $image;
|
||||
unset($refs['_upload']);
|
||||
|
||||
return $refs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Support;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Öffentlicher Medienbereich der Website ("cms/"). Nur Dateien aus diesem Bereich dürfen in Widgets
|
||||
* verwendet werden. Geschützte Bibliotheksmedien (Inhaltsdateien, Vorschaubilder) sind hier nie wählbar.
|
||||
*/
|
||||
final class PublicMedia
|
||||
{
|
||||
public const PREFIX = 'cms/';
|
||||
|
||||
private const IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'webp', 'gif', 'avif'];
|
||||
|
||||
public static function isPublicPath(mixed $path): bool
|
||||
{
|
||||
return is_string($path)
|
||||
&& str_starts_with($path, self::PREFIX)
|
||||
&& ! str_contains($path, '..')
|
||||
&& preg_match('#^cms/[A-Za-z0-9._\-/]+$#', $path) === 1;
|
||||
}
|
||||
|
||||
public static function url(string $path): string
|
||||
{
|
||||
return route('media.public', ['path' => $path]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bereits vorhandene Bilder im öffentlichen Bereich (veröffentlicht oder zur Veröffentlichung vorgemerkt).
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function imageOptions(): array
|
||||
{
|
||||
$options = [];
|
||||
|
||||
foreach (['media_public', 'cms_incoming'] as $disk) {
|
||||
try {
|
||||
$files = Storage::disk($disk)->allFiles(rtrim(self::PREFIX, '/'));
|
||||
} catch (Throwable) {
|
||||
$files = [];
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
|
||||
|
||||
if (self::isPublicPath($file) && in_array($extension, self::IMAGE_EXTENSIONS, true)) {
|
||||
$options[$file] = substr($file, strlen(self::PREFIX));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ksort($options);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pfad aus dem Zustand eines Upload-Felds (Zeichenkette oder Liste).
|
||||
*/
|
||||
public static function fromUploadState(mixed $state): ?string
|
||||
{
|
||||
if (is_array($state)) {
|
||||
$state = array_values($state)[0] ?? null;
|
||||
}
|
||||
|
||||
return is_string($state) && $state !== '' ? $state : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bildadresse für Darstellung und Blockvorschau. In der Vorschau kann ein noch nicht gespeicherter Upload vorliegen.
|
||||
*
|
||||
* @param array<string, mixed> $refs
|
||||
*/
|
||||
public static function imageUrl(array $refs, string $key = 'image'): ?string
|
||||
{
|
||||
$upload = $refs['_upload'] ?? null;
|
||||
$upload = is_array($upload) ? (array_values($upload)[0] ?? null) : $upload;
|
||||
|
||||
if ($upload instanceof TemporaryUploadedFile) {
|
||||
try {
|
||||
return $upload->temporaryUrl();
|
||||
} catch (Throwable) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (self::isPublicPath($upload)) {
|
||||
return self::url($upload);
|
||||
}
|
||||
|
||||
$path = $refs[$key] ?? null;
|
||||
|
||||
return self::isPublicPath($path) ? self::url($path) : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Support;
|
||||
|
||||
use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
|
||||
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
|
||||
|
||||
/**
|
||||
* Formatierter Text in Widgets: feste Auswahl an Auszeichnungen, kein freies HTML, keine Skripte.
|
||||
* Bereinigt wird beim Speichern und erneut bei der Darstellung.
|
||||
*/
|
||||
final class RichText
|
||||
{
|
||||
/** Werkzeugleiste des Editors; muss zur Erlaubnisliste unten passen. */
|
||||
public const TOOLBAR = [['bold', 'italic', 'link'], ['bulletList', 'orderedList'], ['undo', 'redo']];
|
||||
|
||||
private static ?HtmlSanitizer $sanitizer = null;
|
||||
|
||||
public static function sanitize(?string $html): string
|
||||
{
|
||||
if ($html === null || trim($html) === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return trim(self::sanitizer()->sanitize($html));
|
||||
}
|
||||
|
||||
/**
|
||||
* Übernimmt Klartext aus dem Altbestand: Absätze an Leerzeilen, Zeichen maskiert.
|
||||
*/
|
||||
public static function fromPlainText(?string $text): string
|
||||
{
|
||||
$text = trim((string) $text);
|
||||
|
||||
if ($text === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$paragraphs = preg_split("/\n\s*\n/", $text) ?: [];
|
||||
|
||||
return implode('', array_map(
|
||||
fn (string $paragraph): string => '<p>'.e(trim($paragraph)).'</p>',
|
||||
$paragraphs,
|
||||
));
|
||||
}
|
||||
|
||||
public static function isBlank(?string $html): bool
|
||||
{
|
||||
return trim(html_entity_decode(strip_tags((string) $html), ENT_QUOTES | ENT_HTML5, 'UTF-8')) === '';
|
||||
}
|
||||
|
||||
public static function excerpt(?string $html, int $length = 80): string
|
||||
{
|
||||
$text = trim(preg_replace('/\s+/u', ' ', html_entity_decode(strip_tags(str_replace('<', ' <', (string) $html)), ENT_QUOTES | ENT_HTML5, 'UTF-8')) ?? '');
|
||||
|
||||
return mb_strlen($text) > $length ? rtrim(mb_substr($text, 0, $length - 1)).'…' : $text;
|
||||
}
|
||||
|
||||
private static function sanitizer(): HtmlSanitizer
|
||||
{
|
||||
return self::$sanitizer ??= new HtmlSanitizer(
|
||||
(new HtmlSanitizerConfig)
|
||||
->allowElement('p')
|
||||
->allowElement('br')
|
||||
->allowElement('strong')
|
||||
->allowElement('b')
|
||||
->allowElement('em')
|
||||
->allowElement('i')
|
||||
->allowElement('ul')
|
||||
->allowElement('ol')
|
||||
->allowElement('li')
|
||||
->allowElement('a', ['href'])
|
||||
->allowLinkSchemes(['http', 'https', 'mailto'])
|
||||
->allowRelativeLinks()
|
||||
->forceAttribute('a', 'rel', 'noopener')
|
||||
->withMaxInputLength(40000),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Support;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
/**
|
||||
* Zulässige Linkziele in redaktionellen Inhalten: Seitenpfade ("/...") oder http(s)-Adressen.
|
||||
*/
|
||||
final class SafeUrl implements ValidationRule
|
||||
{
|
||||
public static function isSafe(mixed $url): bool
|
||||
{
|
||||
if (! is_string($url) || $url === '' || preg_match('/[\s\x00-\x1F\x7F]/', $url) === 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$isRelative = str_starts_with($url, '/') && ! str_starts_with($url, '//') && ! str_starts_with($url, '/\\');
|
||||
$isAbsolute = preg_match('#^https?://[^/\s]+#i', $url) === 1;
|
||||
|
||||
return $isRelative || $isAbsolute;
|
||||
}
|
||||
|
||||
public static function message(): string
|
||||
{
|
||||
return 'Erlaubt sind Seitenpfade (beginnend mit /) oder http(s)-Adressen.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüfregel für Formularfelder.
|
||||
*/
|
||||
public static function rule(): self
|
||||
{
|
||||
return new self;
|
||||
}
|
||||
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if ($value !== null && $value !== '' && ! self::isSafe($value)) {
|
||||
$fail(self::message());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Types;
|
||||
|
||||
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;
|
||||
|
||||
class CallToActionWidget extends WidgetType
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'call_to_action';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Handlungsaufruf';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Hervorgehobene Fläche mit Überschrift, Text und einer Schaltfläche.';
|
||||
}
|
||||
|
||||
public function icon(): string
|
||||
{
|
||||
return 'heroicon-o-megaphone';
|
||||
}
|
||||
|
||||
public function schematic(): array
|
||||
{
|
||||
return [[2, 4, 56, 28, 'ink'], [8, 9, 30, 4, 'line'], [8, 16, 40, 3, 'line'], [8, 23, 16, 5, 'accent']];
|
||||
}
|
||||
|
||||
public function dataRules(): array
|
||||
{
|
||||
return [
|
||||
'heading' => ['required', 'string', 'max:200'],
|
||||
'text' => ['nullable', 'string', 'max:1000'],
|
||||
'label' => ['required', 'string', 'max:80'],
|
||||
'url' => ['required', 'string', 'max:500'],
|
||||
];
|
||||
}
|
||||
|
||||
public function dataFields(): array
|
||||
{
|
||||
return [
|
||||
TextInput::make('heading')->label('Überschrift')->required()->maxLength(200),
|
||||
Textarea::make('text')->label('Text')->rows(3)->maxLength(1000),
|
||||
TextInput::make('label')->label('Beschriftung der Schaltfläche')->required()->maxLength(80),
|
||||
TextInput::make('url')
|
||||
->label('Linkziel')
|
||||
->required()
|
||||
->maxLength(500)
|
||||
->rule(SafeUrl::rule())
|
||||
->helperText('Seitenpfad wie /angebote oder eine vollständige http(s)-Adresse.'),
|
||||
];
|
||||
}
|
||||
|
||||
public function clean(array $data, array $refs, WidgetErrors $errors): array
|
||||
{
|
||||
if (! SafeUrl::isSafe($data['url'] ?? null)) {
|
||||
$errors->add('data.url', SafeUrl::message());
|
||||
}
|
||||
|
||||
return [$data, $refs];
|
||||
}
|
||||
|
||||
public function summary(array $widget): string
|
||||
{
|
||||
return trim(($widget['data']['heading'] ?? '').' → '.($widget['data']['label'] ?? ''));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Types;
|
||||
|
||||
use App\Domain\Cms\Widgets\RenderContext;
|
||||
use App\Domain\Cms\Widgets\Support\ImageRefFields;
|
||||
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\Repeater;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
|
||||
/**
|
||||
* Redaktionelle Karten. Die Einträge sind freie redaktionelle Verweise, keine Produkte oder Lizenzartikel.
|
||||
*
|
||||
* Version 1 umfasst den Bestand (Titel, Text, Adresse). Das optionale Bild je Karte ist eine
|
||||
* abwärtskompatible Ergänzung derselben Version: ältere Karten haben schlicht kein Bild.
|
||||
*/
|
||||
class CardsWidget extends WidgetType
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'cards';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Redaktionelle Karten';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Mehrere Karten mit Titel, Text, Linkziel und optionalem Bild. Als Raster oder kompakte Liste.';
|
||||
}
|
||||
|
||||
public function icon(): string
|
||||
{
|
||||
return 'heroicon-o-squares-2x2';
|
||||
}
|
||||
|
||||
public function schematic(): array
|
||||
{
|
||||
return [[2, 6, 17, 24, 'line'], [21, 6, 17, 24, 'line'], [40, 6, 17, 24, 'line'], [2, 6, 17, 2, 'accent'], [21, 6, 17, 2, 'accent'], [40, 6, 17, 2, 'accent']];
|
||||
}
|
||||
|
||||
public function variants(): array
|
||||
{
|
||||
return [
|
||||
'standard' => 'Raster',
|
||||
'compact' => 'Kompakte Liste',
|
||||
];
|
||||
}
|
||||
|
||||
public function dataRules(): array
|
||||
{
|
||||
return [
|
||||
'items' => ['required', 'array', 'min:1', 'max:12'],
|
||||
'items.*.title' => ['required', 'string', 'max:120'],
|
||||
'items.*.text' => ['nullable', 'string', 'max:500'],
|
||||
'items.*.url' => ['nullable', 'string', 'max:500'],
|
||||
'items.*.image' => ['nullable', 'string', 'max:255'],
|
||||
'items.*._upload' => ['nullable'],
|
||||
];
|
||||
}
|
||||
|
||||
public function dataFields(): array
|
||||
{
|
||||
[$image, $upload] = ImageRefFields::fields('Bild (optional)');
|
||||
|
||||
return [
|
||||
Repeater::make('items')
|
||||
->label('Karten')
|
||||
->schema([
|
||||
TextInput::make('title')->label('Titel')->required()->maxLength(120),
|
||||
Textarea::make('text')->label('Beschreibung')->rows(2)->maxLength(500),
|
||||
TextInput::make('url')
|
||||
->label('Linkziel')
|
||||
->maxLength(500)
|
||||
->rule(SafeUrl::rule())
|
||||
->helperText('Seitenpfad wie /praevention oder eine http(s)-Adresse. Leer lassen für eine Karte ohne Link.'),
|
||||
$image,
|
||||
$upload,
|
||||
])
|
||||
->minItems(1)
|
||||
->maxItems(12)
|
||||
->reorderableWithButtons()
|
||||
->collapsible()
|
||||
->cloneable()
|
||||
->itemLabel(fn (array $state): ?string => $state['title'] ?? null)
|
||||
->addActionLabel('Karte hinzufügen'),
|
||||
];
|
||||
}
|
||||
|
||||
public function clean(array $data, array $refs, WidgetErrors $errors): array
|
||||
{
|
||||
foreach ($data['items'] as $index => $item) {
|
||||
if (filled($item['url'] ?? null) && ! SafeUrl::isSafe($item['url'])) {
|
||||
$errors->add("data.items.$index.url", SafeUrl::message());
|
||||
}
|
||||
|
||||
$itemRefs = ImageRefFields::clean(['image' => $item['image'] ?? null, '_upload' => $item['_upload'] ?? null], $errors, errorKey: "data.items.$index.image");
|
||||
|
||||
$data['items'][$index] = [
|
||||
'title' => $item['title'],
|
||||
'text' => filled($item['text'] ?? null) ? $item['text'] : null,
|
||||
'url' => filled($item['url'] ?? null) ? $item['url'] : null,
|
||||
'image' => $itemRefs['image'],
|
||||
];
|
||||
}
|
||||
|
||||
return [$data, $refs];
|
||||
}
|
||||
|
||||
public function resolve(array $widget, RenderContext $context): array
|
||||
{
|
||||
$items = [];
|
||||
|
||||
foreach ($widget['data']['items'] ?? [] as $item) {
|
||||
if (! is_array($item) || ! filled($item['title'] ?? null)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$items[] = [
|
||||
'title' => $item['title'],
|
||||
'text' => $item['text'] ?? null,
|
||||
'url' => SafeUrl::isSafe($item['url'] ?? null) ? $item['url'] : null,
|
||||
'imageUrl' => PublicMedia::imageUrl($item),
|
||||
];
|
||||
}
|
||||
|
||||
return ['items' => $items];
|
||||
}
|
||||
|
||||
public function mediaPaths(array $widget): array
|
||||
{
|
||||
$paths = [];
|
||||
|
||||
foreach ($widget['data']['items'] ?? [] as $item) {
|
||||
if (is_array($item) && PublicMedia::isPublicPath($item['image'] ?? null)) {
|
||||
$paths[] = $item['image'];
|
||||
}
|
||||
}
|
||||
|
||||
return $paths;
|
||||
}
|
||||
|
||||
public function summary(array $widget): string
|
||||
{
|
||||
$titles = array_filter(array_map(fn ($item) => is_array($item) ? ($item['title'] ?? null) : null, $widget['data']['items'] ?? []));
|
||||
|
||||
return count($titles).' Karten: '.implode(', ', $titles);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Types;
|
||||
|
||||
use App\Domain\Catalog\Composition;
|
||||
use App\Domain\Cms\Catalog\PublicCatalogReader;
|
||||
use App\Domain\Cms\Widgets\RenderContext;
|
||||
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||
use App\Domain\Cms\Widgets\WidgetType;
|
||||
use Filament\Forms\Components\Hidden;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
|
||||
/**
|
||||
* Kuratierte Programm- und Modulkarten.
|
||||
*
|
||||
* Gespeichert werden nur Verweise (refs.items: [{type: 'composition', id}]) und Darstellungswahl.
|
||||
* Titel, Kurzbeschreibung und Inhaltsart kommen zur Laufzeit aus den Fachdaten (PublicCatalogReader).
|
||||
* Eine Karte begründet keine Nutzungsberechtigung und ist kein Lizenzartikel.
|
||||
*/
|
||||
class CatalogCardsWidget extends WidgetType
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'catalog_cards';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Programm- und Modulkarten';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Ausgewählte Programme und Module; Titel und Beschreibung kommen automatisch aus den Fachdaten.';
|
||||
}
|
||||
|
||||
public function icon(): string
|
||||
{
|
||||
return 'heroicon-o-rectangle-stack';
|
||||
}
|
||||
|
||||
public function schematic(): array
|
||||
{
|
||||
return [[2, 4, 26, 28, 'line'], [32, 4, 26, 28, 'line'], [5, 7, 20, 9, 'image'], [35, 7, 20, 9, 'image'], [5, 19, 18, 3, 'ink'], [35, 19, 18, 3, 'ink'], [5, 25, 8, 3, 'accent'], [35, 25, 8, 3, 'accent']];
|
||||
}
|
||||
|
||||
public function variants(): array
|
||||
{
|
||||
return [
|
||||
'standard' => 'Karten mit Kurzbeschreibung',
|
||||
'compact' => 'Kompakte Liste',
|
||||
];
|
||||
}
|
||||
|
||||
public function dataRules(): array
|
||||
{
|
||||
return [
|
||||
'heading' => ['nullable', 'string', 'max:160'],
|
||||
'intro' => ['nullable', 'string', 'max:400'],
|
||||
];
|
||||
}
|
||||
|
||||
public function refRules(): array
|
||||
{
|
||||
return [
|
||||
'items' => ['required', 'array', 'min:1', 'max:12'],
|
||||
'items.*.type' => ['required', 'string', 'in:composition'],
|
||||
'items.*.id' => ['required', 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
public function dataFields(): array
|
||||
{
|
||||
return [
|
||||
TextInput::make('heading')->label('Abschnittsüberschrift (optional)')->maxLength(160),
|
||||
Textarea::make('intro')->label('Einleitung (optional)')->rows(2)->maxLength(400),
|
||||
];
|
||||
}
|
||||
|
||||
public function refFields(): array
|
||||
{
|
||||
return [
|
||||
Repeater::make('items')
|
||||
->label('Programme und Module')
|
||||
->helperText('Nur zur Anzeige freigegebene Programme und Module sind wählbar. Öffentlich erscheinen derzeit nur Programme mit öffentlicher Programmseite; Module nur in der Redaktionsvorschau.')
|
||||
->schema([
|
||||
Hidden::make('type')->default('composition'),
|
||||
Select::make('id')
|
||||
->label('Programm oder Modul')
|
||||
->required()
|
||||
->live()
|
||||
->searchable()
|
||||
->getSearchResultsUsing(fn (?string $search): array => app(PublicCatalogReader::class)->search($search))
|
||||
->getOptionLabelUsing(fn (mixed $value): ?string => app(PublicCatalogReader::class)->labelFor($value))
|
||||
->options(fn (): array => app(PublicCatalogReader::class)->search(null, 10)),
|
||||
])
|
||||
->minItems(1)
|
||||
->maxItems(12)
|
||||
->reorderableWithButtons()
|
||||
->itemLabel(fn (array $state): ?string => filled($state['id'] ?? null) ? app(PublicCatalogReader::class)->labelFor($state['id']) : null)
|
||||
->addActionLabel('Programm oder Modul hinzufügen'),
|
||||
];
|
||||
}
|
||||
|
||||
public function clean(array $data, array $refs, WidgetErrors $errors): array
|
||||
{
|
||||
$reader = app(PublicCatalogReader::class);
|
||||
$items = [];
|
||||
$seen = [];
|
||||
|
||||
foreach ($refs['items'] as $index => $item) {
|
||||
$id = (int) $item['id'];
|
||||
$composition = Composition::query()->with('editorialContentKind')->find($id);
|
||||
|
||||
if ($composition === null || ! $reader->isSelectable($composition)) {
|
||||
$errors->add("refs.items.$index.id", 'Dieses Objekt ist kein zur Anzeige freigegebenes Programm oder Modul.');
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($seen[$id])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$seen[$id] = true;
|
||||
$items[] = ['type' => 'composition', 'id' => $id];
|
||||
}
|
||||
|
||||
$refs['items'] = $items;
|
||||
|
||||
foreach (['heading', 'intro'] as $key) {
|
||||
$data[$key] = filled($data[$key] ?? null) ? trim($data[$key]) : null;
|
||||
}
|
||||
|
||||
return [$data, $refs];
|
||||
}
|
||||
|
||||
public function resolve(array $widget, RenderContext $context): array
|
||||
{
|
||||
$refs = is_array($widget['refs']['items'] ?? null) ? array_values($widget['refs']['items']) : [];
|
||||
|
||||
return [
|
||||
'entries' => app(PublicCatalogReader::class)->entries($refs, includeNonPublic: $context->preview),
|
||||
];
|
||||
}
|
||||
|
||||
public function summary(array $widget): string
|
||||
{
|
||||
$count = count($widget['refs']['items'] ?? []);
|
||||
$heading = $widget['data']['heading'] ?? null;
|
||||
|
||||
return trim(($heading ? $heading.' · ' : '').($count === 1 ? '1 Verweis' : $count.' Verweise'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Types;
|
||||
|
||||
use App\Domain\Cms\Widgets\WidgetType;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
|
||||
class FaqWidget extends WidgetType
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'faq';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'FAQ';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Häufige Fragen mit Antworten.';
|
||||
}
|
||||
|
||||
public function icon(): string
|
||||
{
|
||||
return 'heroicon-o-question-mark-circle';
|
||||
}
|
||||
|
||||
public function schematic(): array
|
||||
{
|
||||
return [[4, 5, 34, 3, 'ink'], [4, 10, 50, 3, 'line'], [4, 17, 30, 3, 'ink'], [4, 22, 46, 3, 'line'], [4, 29, 38, 3, 'ink']];
|
||||
}
|
||||
|
||||
public function dataRules(): array
|
||||
{
|
||||
return [
|
||||
'items' => ['required', 'array', 'min:1', 'max:20'],
|
||||
'items.*.question' => ['required', 'string', 'max:300'],
|
||||
'items.*.answer' => ['required', 'string', 'max:2000'],
|
||||
];
|
||||
}
|
||||
|
||||
public function dataFields(): array
|
||||
{
|
||||
return [
|
||||
Repeater::make('items')
|
||||
->label('Fragen')
|
||||
->schema([
|
||||
TextInput::make('question')->label('Frage')->required()->maxLength(300),
|
||||
Textarea::make('answer')->label('Antwort')->rows(3)->required()->maxLength(2000),
|
||||
])
|
||||
->minItems(1)
|
||||
->maxItems(20)
|
||||
->reorderableWithButtons()
|
||||
->collapsible()
|
||||
->itemLabel(fn (array $state): ?string => $state['question'] ?? null)
|
||||
->addActionLabel('Frage hinzufügen'),
|
||||
];
|
||||
}
|
||||
|
||||
public function summary(array $widget): string
|
||||
{
|
||||
$count = count($widget['data']['items'] ?? []);
|
||||
|
||||
return $count === 1 ? '1 Frage' : $count.' Fragen';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Types;
|
||||
|
||||
use App\Domain\Cms\Widgets\WidgetType;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
|
||||
class HeadingWidget extends WidgetType
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'heading';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Überschrift und Einleitung';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Abschnittsüberschrift mit kurzem Einleitungstext.';
|
||||
}
|
||||
|
||||
public function icon(): string
|
||||
{
|
||||
return 'heroicon-o-h1';
|
||||
}
|
||||
|
||||
public function schematic(): array
|
||||
{
|
||||
return [[4, 8, 40, 6, 'ink'], [4, 19, 50, 3, 'line'], [4, 25, 36, 3, 'line']];
|
||||
}
|
||||
|
||||
public function dataRules(): array
|
||||
{
|
||||
return [
|
||||
'heading' => ['required', 'string', 'max:200'],
|
||||
'intro' => ['nullable', 'string', 'max:1000'],
|
||||
];
|
||||
}
|
||||
|
||||
public function dataFields(): array
|
||||
{
|
||||
return [
|
||||
TextInput::make('heading')->label('Überschrift')->required()->maxLength(200),
|
||||
Textarea::make('intro')->label('Einleitung')->rows(3)->maxLength(1000),
|
||||
];
|
||||
}
|
||||
|
||||
public function summary(array $widget): string
|
||||
{
|
||||
return (string) ($widget['data']['heading'] ?? '');
|
||||
}
|
||||
|
||||
public function pageTitle(array $widget): ?string
|
||||
{
|
||||
return $widget['data']['heading'] ?? null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Types;
|
||||
|
||||
use App\Domain\Cms\Widgets\RenderContext;
|
||||
use App\Domain\Cms\Widgets\Support\ImageRefFields;
|
||||
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;
|
||||
|
||||
class HeroWidget extends WidgetType
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'hero';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Einstieg (Hero)';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Großer Seiteneinstieg mit Überschrift, Beschreibung, optionalem Bild und optionaler Schaltfläche.';
|
||||
}
|
||||
|
||||
public function icon(): string
|
||||
{
|
||||
return 'heroicon-o-sparkles';
|
||||
}
|
||||
|
||||
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']];
|
||||
}
|
||||
|
||||
public function variants(): array
|
||||
{
|
||||
return [
|
||||
'standard' => 'Standard (Bild neben dem Text)',
|
||||
'highlight' => 'Hervorgehoben (Markenfläche)',
|
||||
];
|
||||
}
|
||||
|
||||
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'],
|
||||
'alt' => ['nullable', 'string', 'max:300'],
|
||||
];
|
||||
}
|
||||
|
||||
public function refRules(): array
|
||||
{
|
||||
return ImageRefFields::rules();
|
||||
}
|
||||
|
||||
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'),
|
||||
]),
|
||||
TextInput::make('alt')
|
||||
->label('Alternativtext des Bildes')
|
||||
->maxLength(300)
|
||||
->helperText('Pflicht, sobald ein Bild gewählt ist.'),
|
||||
];
|
||||
}
|
||||
|
||||
public function refFields(): array
|
||||
{
|
||||
return ImageRefFields::fields();
|
||||
}
|
||||
|
||||
public function editorSchema(): array
|
||||
{
|
||||
[$heading, $text, $cta, $alt] = $this->dataFields();
|
||||
|
||||
return [
|
||||
Group::make([$heading, $text, $cta])->statePath('data'),
|
||||
Group::make($this->refFields())->statePath('refs'),
|
||||
Group::make([$alt])->statePath('data'),
|
||||
];
|
||||
}
|
||||
|
||||
public function clean(array $data, array $refs, WidgetErrors $errors): array
|
||||
{
|
||||
$refs = ImageRefFields::clean($refs, $errors);
|
||||
|
||||
foreach (['text', 'cta_label', 'cta_url', 'alt'] as $key) {
|
||||
$data[$key] = filled($data[$key] ?? null) ? trim($data[$key]) : null;
|
||||
}
|
||||
|
||||
if ($data['cta_url'] !== null && ! SafeUrl::isSafe($data['cta_url'])) {
|
||||
$errors->add('data.cta_url', SafeUrl::message());
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
$data = $widget['data'];
|
||||
$hasAction = filled($data['cta_label'] ?? null) && SafeUrl::isSafe($data['cta_url'] ?? null);
|
||||
|
||||
return [
|
||||
'imageUrl' => PublicMedia::imageUrl($widget['refs']),
|
||||
'action' => $hasAction ? ['label' => $data['cta_label'], 'url' => $data['cta_url']] : null,
|
||||
];
|
||||
}
|
||||
|
||||
public function mediaPaths(array $widget): array
|
||||
{
|
||||
$image = $widget['refs']['image'] ?? null;
|
||||
|
||||
return PublicMedia::isPublicPath($image) ? [$image] : [];
|
||||
}
|
||||
|
||||
public function summary(array $widget): string
|
||||
{
|
||||
return (string) ($widget['data']['heading'] ?? '');
|
||||
}
|
||||
|
||||
public function pageTitle(array $widget): ?string
|
||||
{
|
||||
return $widget['data']['heading'] ?? null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Types;
|
||||
|
||||
use App\Domain\Cms\Widgets\RenderContext;
|
||||
use App\Domain\Cms\Widgets\Support\ImageRefFields;
|
||||
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
||||
use App\Domain\Cms\Widgets\Support\RichText;
|
||||
use App\Domain\Cms\Widgets\WidgetErrors;
|
||||
use App\Domain\Cms\Widgets\WidgetType;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Components\Group;
|
||||
|
||||
/**
|
||||
* Bild und Text.
|
||||
*
|
||||
* Version 1 (Bestand): data {image, alt, body} mit Klartext.
|
||||
* Version 2: data {title, body (formatierter Text), alt}, refs {image}, Varianten Bild links/rechts.
|
||||
*/
|
||||
class ImageTextWidget extends WidgetType
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'image_text';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Bild und Text';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Bild neben formatiertem Text; Bild links oder rechts, auf dem Smartphone untereinander.';
|
||||
}
|
||||
|
||||
public function version(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function icon(): string
|
||||
{
|
||||
return 'heroicon-o-photo';
|
||||
}
|
||||
|
||||
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']];
|
||||
}
|
||||
|
||||
public function variants(): array
|
||||
{
|
||||
return [
|
||||
'image_left' => 'Bild links',
|
||||
'image_right' => 'Bild rechts',
|
||||
];
|
||||
}
|
||||
|
||||
public function upgrade(array $widget, int $from): array
|
||||
{
|
||||
if ($from !== 1) {
|
||||
return parent::upgrade($widget, $from);
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
public function dataRules(): array
|
||||
{
|
||||
return [
|
||||
'title' => ['nullable', 'string', 'max:160'],
|
||||
'body' => ['required', 'string', 'max:40000'],
|
||||
'alt' => ['nullable', 'string', 'max:300'],
|
||||
];
|
||||
}
|
||||
|
||||
public function refRules(): array
|
||||
{
|
||||
return ImageRefFields::rules();
|
||||
}
|
||||
|
||||
public function dataFields(): array
|
||||
{
|
||||
return [
|
||||
TextInput::make('title')->label('Titel (optional)')->maxLength(160),
|
||||
RichEditor::make('body')
|
||||
->label('Text')
|
||||
->required()
|
||||
->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.'),
|
||||
];
|
||||
}
|
||||
|
||||
public function refFields(): array
|
||||
{
|
||||
return ImageRefFields::fields();
|
||||
}
|
||||
|
||||
public function editorSchema(): array
|
||||
{
|
||||
[$title, $body, $alt] = $this->dataFields();
|
||||
|
||||
return [
|
||||
Group::make([$title, $body])->statePath('data'),
|
||||
Group::make($this->refFields())->statePath('refs'),
|
||||
Group::make([$alt])->statePath('data'),
|
||||
];
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
{
|
||||
return [
|
||||
'imageUrl' => PublicMedia::imageUrl($widget['refs']),
|
||||
'body' => RichText::sanitize(is_string($widget['data']['body'] ?? null) ? $widget['data']['body'] : ''),
|
||||
];
|
||||
}
|
||||
|
||||
public function mediaPaths(array $widget): array
|
||||
{
|
||||
$image = $widget['refs']['image'] ?? null;
|
||||
|
||||
return PublicMedia::isPublicPath($image) ? [$image] : [];
|
||||
}
|
||||
|
||||
public function summary(array $widget): string
|
||||
{
|
||||
$title = $widget['data']['title'] ?? null;
|
||||
|
||||
return filled($title) ? (string) $title : RichText::excerpt($widget['data']['body'] ?? '');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets\Types;
|
||||
|
||||
use App\Domain\Cms\Widgets\Support\RichText;
|
||||
use App\Domain\Cms\Widgets\WidgetType;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
|
||||
class ProseWidget extends WidgetType
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'prose';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Fließtext';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Längerer Text in Absätzen. Eine Leerzeile beginnt einen neuen Absatz.';
|
||||
}
|
||||
|
||||
public function icon(): string
|
||||
{
|
||||
return 'heroicon-o-bars-3-bottom-left';
|
||||
}
|
||||
|
||||
public function dataRules(): array
|
||||
{
|
||||
return [
|
||||
'body' => ['required', 'string', 'max:20000'],
|
||||
];
|
||||
}
|
||||
|
||||
public function dataFields(): array
|
||||
{
|
||||
return [
|
||||
Textarea::make('body')
|
||||
->label('Text')
|
||||
->rows(10)
|
||||
->required()
|
||||
->maxLength(20000)
|
||||
->helperText('Eine Leerzeile beginnt einen neuen Absatz.'),
|
||||
];
|
||||
}
|
||||
|
||||
public function summary(array $widget): string
|
||||
{
|
||||
return RichText::excerpt(e((string) ($widget['data']['body'] ?? '')));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets;
|
||||
|
||||
/**
|
||||
* Sammelt Prüfmeldungen einer Widget-Instanz mit Schlüsseln relativ zur Hülle (zum Beispiel 'data.url').
|
||||
*/
|
||||
class WidgetErrors
|
||||
{
|
||||
/** @var array<string, list<string>> */
|
||||
private array $messages = [];
|
||||
|
||||
public function add(string $key, string $message): void
|
||||
{
|
||||
$this->messages[$key][] = $message;
|
||||
}
|
||||
|
||||
public function isEmpty(): bool
|
||||
{
|
||||
return $this->messages === [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, list<string>>
|
||||
*/
|
||||
public function all(): array
|
||||
{
|
||||
return $this->messages;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets;
|
||||
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Zentrales, codebasiertes Widget-Register (ADR-30).
|
||||
*
|
||||
* Lesepfad: upcast() hebt jeden gespeicherten Baustein (Altformat ohne Hülle oder Hülle älterer Version)
|
||||
* auf die aktuelle Hülle an, ohne die gespeicherte Revision zu verändern.
|
||||
* Schreibpfad: normalize() prüft und bereinigt Bausteine aus dem Editor und liefert Hüllen der aktuellen Version.
|
||||
*/
|
||||
class WidgetRegistry
|
||||
{
|
||||
/** @var array<string, WidgetType> */
|
||||
private array $types = [];
|
||||
|
||||
/**
|
||||
* @param iterable<WidgetType> $types
|
||||
*/
|
||||
public function __construct(iterable $types = [])
|
||||
{
|
||||
foreach ($types as $type) {
|
||||
$this->register($type);
|
||||
}
|
||||
}
|
||||
|
||||
public function register(WidgetType $type): void
|
||||
{
|
||||
$key = $type->key();
|
||||
|
||||
if (preg_match('/^[a-z][a-z0-9_]{1,40}$/', $key) !== 1) {
|
||||
throw new InvalidArgumentException("Ungültige Widget-Kennung „{$key}“.");
|
||||
}
|
||||
|
||||
if (isset($this->types[$key])) {
|
||||
throw new InvalidArgumentException("Die Widget-Kennung „{$key}“ ist bereits registriert.");
|
||||
}
|
||||
|
||||
if ($type->version() < 1) {
|
||||
throw new InvalidArgumentException("Widget „{$key}“ braucht eine Schemaversion ab 1.");
|
||||
}
|
||||
|
||||
if ($type->variants() === []) {
|
||||
throw new InvalidArgumentException("Widget „{$key}“ braucht mindestens eine Darstellungsvariante.");
|
||||
}
|
||||
|
||||
foreach (array_keys($type->variants()) as $variant) {
|
||||
if (preg_match('/^[a-z][a-z0-9_]*$/', (string) $variant) !== 1) {
|
||||
throw new InvalidArgumentException("Widget „{$key}“ hat eine ungültige Variantenkennung.");
|
||||
}
|
||||
}
|
||||
|
||||
$this->types[$key] = $type;
|
||||
}
|
||||
|
||||
public function has(mixed $key): bool
|
||||
{
|
||||
return is_string($key) && isset($this->types[$key]);
|
||||
}
|
||||
|
||||
public function get(string $key): WidgetType
|
||||
{
|
||||
return $this->types[$key] ?? throw new InvalidArgumentException("Unbekannte Widget-Art „{$key}“.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, WidgetType>
|
||||
*/
|
||||
public function all(): array
|
||||
{
|
||||
return $this->types;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function labels(): array
|
||||
{
|
||||
return array_map(fn (WidgetType $type): string => $type->label(), $this->types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hebt einen gespeicherten Baustein auf die aktuelle Hülle an. Unbekannte Arten liefern null.
|
||||
*
|
||||
* @param array<string, mixed> $block
|
||||
* @return array{id: ?string, type: string, v: int, variant: string, settings: array<string, mixed>, data: array<string, mixed>, refs: array<string, mixed>}|null
|
||||
*/
|
||||
public function upcast(array $block): ?array
|
||||
{
|
||||
$key = $block['type'] ?? null;
|
||||
|
||||
if (! $this->has($key)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$type = $this->get($key);
|
||||
|
||||
if (array_key_exists('v', $block)) {
|
||||
$widget = [
|
||||
'id' => is_string($block['id'] ?? null) ? $block['id'] : null,
|
||||
'type' => $key,
|
||||
'v' => max(1, (int) $block['v']),
|
||||
'variant' => is_string($block['variant'] ?? null) ? $block['variant'] : $type->defaultVariant(),
|
||||
'settings' => is_array($block['settings'] ?? null) ? $block['settings'] : [],
|
||||
'data' => is_array($block['data'] ?? null) ? $block['data'] : [],
|
||||
'refs' => is_array($block['refs'] ?? null) ? $block['refs'] : [],
|
||||
];
|
||||
} else {
|
||||
$legacy = $type->fromLegacy($block);
|
||||
$widget = [
|
||||
'id' => null,
|
||||
'type' => $key,
|
||||
'v' => 1,
|
||||
'variant' => $legacy['variant'] ?? $type->defaultVariant(),
|
||||
'settings' => [],
|
||||
'data' => $legacy['data'],
|
||||
'refs' => $legacy['refs'],
|
||||
];
|
||||
}
|
||||
|
||||
while ($widget['v'] < $type->version()) {
|
||||
$from = $widget['v'];
|
||||
$widget = $type->upgrade($widget, $from);
|
||||
$widget['v'] = $from + 1;
|
||||
}
|
||||
|
||||
if (! array_key_exists($widget['variant'], $type->variants())) {
|
||||
$widget['variant'] = $type->defaultVariant();
|
||||
}
|
||||
|
||||
return $widget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft und bereinigt Bausteine für eine neue Revision.
|
||||
*
|
||||
* @param array<int|string, mixed> $blocks
|
||||
* @return list<array{id: string, type: string, v: int, variant: string, settings: array<string, mixed>, data: array<string, mixed>, refs: array<string, mixed>}>
|
||||
*/
|
||||
public function normalize(array $blocks): array
|
||||
{
|
||||
$normalized = [];
|
||||
$seenIds = [];
|
||||
|
||||
foreach (array_values($blocks) as $index => $block) {
|
||||
if (! is_array($block)) {
|
||||
throw ValidationException::withMessages([
|
||||
"blocks.$index" => 'Ein Baustein ist unvollständig.',
|
||||
]);
|
||||
}
|
||||
|
||||
if (! $this->has($block['type'] ?? null)) {
|
||||
throw ValidationException::withMessages([
|
||||
"blocks.$index.type" => 'Dieser Bausteintyp ist nicht freigegeben.',
|
||||
]);
|
||||
}
|
||||
|
||||
$type = $this->get($block['type']);
|
||||
|
||||
if (array_key_exists('v', $block) && (int) $block['v'] > $type->version()) {
|
||||
throw ValidationException::withMessages([
|
||||
"blocks.$index.v" => 'Dieser Baustein stammt aus einer neueren Programmfassung und kann hier nicht gespeichert werden.',
|
||||
]);
|
||||
}
|
||||
|
||||
$requested = $block['variant'] ?? null;
|
||||
$isCurrent = array_key_exists('v', $block) && (int) $block['v'] === $type->version();
|
||||
|
||||
if ($isCurrent && is_string($requested) && $requested !== '' && ! array_key_exists($requested, $type->variants())) {
|
||||
throw ValidationException::withMessages([
|
||||
"blocks.$index.variant" => 'Diese Darstellungsvariante ist für den Baustein nicht freigegeben.',
|
||||
]);
|
||||
}
|
||||
|
||||
$widget = $this->upcast($block);
|
||||
$normalized[] = $this->validateOne($type, $widget, $index, $seenIds);
|
||||
}
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gespeicherte Bausteine einer Revision als aktuelle Hüllen; unbekannte Arten entfallen.
|
||||
*
|
||||
* @param array<int|string, mixed>|null $blocks
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function read(?array $blocks): array
|
||||
{
|
||||
$widgets = [];
|
||||
|
||||
foreach (array_values($blocks ?? []) as $block) {
|
||||
if (is_array($block) && ($widget = $this->upcast($block)) !== null) {
|
||||
$widgets[] = $widget;
|
||||
}
|
||||
}
|
||||
|
||||
return $widgets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int|string, mixed>|null $blocks
|
||||
*/
|
||||
public function pageTitle(?array $blocks): ?string
|
||||
{
|
||||
foreach ($this->read($blocks) as $widget) {
|
||||
$title = $this->get($widget['type'])->pageTitle($widget);
|
||||
|
||||
if (is_string($title) && trim($title) !== '') {
|
||||
return $title;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int|string, mixed>|null $blocks
|
||||
* @return list<string>
|
||||
*/
|
||||
public function mediaPaths(?array $blocks): array
|
||||
{
|
||||
$paths = [];
|
||||
|
||||
foreach ($this->read($blocks) as $widget) {
|
||||
foreach ($this->get($widget['type'])->mediaPaths($widget) as $path) {
|
||||
$paths[] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique($paths));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $widget
|
||||
* @param array<string, true> $seenIds
|
||||
* @return array{id: string, type: string, v: int, variant: string, settings: array<string, mixed>, data: array<string, mixed>, refs: array<string, mixed>}
|
||||
*/
|
||||
private function validateOne(WidgetType $type, array $widget, int $index, array &$seenIds): array
|
||||
{
|
||||
$errors = new WidgetErrors;
|
||||
|
||||
$variant = $widget['variant'];
|
||||
if (! array_key_exists($variant, $type->variants())) {
|
||||
$errors->add('variant', 'Diese Darstellungsvariante ist für den Baustein nicht freigegeben.');
|
||||
}
|
||||
|
||||
$settings = [];
|
||||
$allowedSettings = $type->settings();
|
||||
foreach ($widget['settings'] as $key => $value) {
|
||||
if ($value === null || $value === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! isset($allowedSettings[$key]) || ! is_string($value) || ! array_key_exists($value, $allowedSettings[$key])) {
|
||||
$errors->add("settings.$key", 'Diese Einstellung ist für den Baustein nicht freigegeben.');
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$settings[$key] = $value;
|
||||
}
|
||||
|
||||
$rules = [];
|
||||
foreach ($type->dataRules() as $key => $rule) {
|
||||
$rules["data.$key"] = $rule;
|
||||
}
|
||||
foreach ($type->refRules() as $key => $rule) {
|
||||
$rules["refs.$key"] = $rule;
|
||||
}
|
||||
|
||||
$validator = Validator::make(['data' => $widget['data'], 'refs' => $widget['refs']], $rules);
|
||||
|
||||
foreach ($validator->errors()->messages() as $key => $messages) {
|
||||
foreach ($messages as $message) {
|
||||
$errors->add($key, $message);
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->onlyDeclared($widget['data'], $type->dataRules());
|
||||
$refs = $this->onlyDeclared($widget['refs'], $type->refRules());
|
||||
|
||||
if ($errors->isEmpty()) {
|
||||
[$data, $refs] = $type->clean($data, $refs, $errors);
|
||||
}
|
||||
|
||||
if (! $errors->isEmpty()) {
|
||||
$messages = [];
|
||||
foreach ($errors->all() as $key => $list) {
|
||||
$messages["blocks.$index.$key"] = $list;
|
||||
}
|
||||
|
||||
throw ValidationException::withMessages($messages);
|
||||
}
|
||||
|
||||
$id = $widget['id'];
|
||||
if (! is_string($id) || preg_match('/^[A-Za-z0-9-]{1,64}$/', $id) !== 1 || isset($seenIds[$id])) {
|
||||
$id = (string) Str::uuid();
|
||||
}
|
||||
$seenIds[$id] = true;
|
||||
|
||||
return [
|
||||
'id' => $id,
|
||||
'type' => $type->key(),
|
||||
'v' => $type->version(),
|
||||
'variant' => $variant,
|
||||
'settings' => $settings,
|
||||
'data' => $this->withoutTransient($data),
|
||||
'refs' => $this->withoutTransient($refs),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Behält nur Schlüssel, für die Prüfregeln bestehen; Listen ('items.*.feld') werden je Eintrag gefiltert.
|
||||
*
|
||||
* @param array<string, mixed> $values
|
||||
* @param array<string, mixed> $rules
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function onlyDeclared(array $values, array $rules): array
|
||||
{
|
||||
$top = [];
|
||||
$nested = [];
|
||||
|
||||
foreach (array_keys($rules) as $key) {
|
||||
if (preg_match('/^([a-z_]+)\.\*\.([a-z_]+)$/', (string) $key, $match) === 1) {
|
||||
$nested[$match[1]][] = $match[2];
|
||||
} elseif (! str_contains((string) $key, '.')) {
|
||||
$top[] = (string) $key;
|
||||
}
|
||||
}
|
||||
|
||||
$clean = [];
|
||||
foreach ($top as $key) {
|
||||
$value = $values[$key] ?? null;
|
||||
|
||||
if (isset($nested[$key])) {
|
||||
$items = [];
|
||||
foreach (array_values(is_array($value) ? $value : []) as $item) {
|
||||
if (! is_array($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$entry = [];
|
||||
foreach ($nested[$key] as $field) {
|
||||
$entry[$field] = $item[$field] ?? null;
|
||||
}
|
||||
$items[] = $entry;
|
||||
}
|
||||
$value = $items;
|
||||
}
|
||||
|
||||
$clean[$key] = $value;
|
||||
}
|
||||
|
||||
return $clean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Felder mit führendem Unterstrich (zum Beispiel '_upload') sind reine Editorhilfen und werden nicht gespeichert.
|
||||
*
|
||||
* @param array<string, mixed> $values
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function withoutTransient(array $values): array
|
||||
{
|
||||
foreach (array_keys($values) as $key) {
|
||||
if (str_starts_with((string) $key, '_')) {
|
||||
unset($values[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets;
|
||||
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
/**
|
||||
* Einziger Darstellungsweg für Widgets: öffentliche Seite, ganzseitige Vorschau und Blockvorschau im Editor
|
||||
* verwenden dieselbe Blade-Ansicht je Widget-Art.
|
||||
*/
|
||||
class WidgetRenderer
|
||||
{
|
||||
public function __construct(private readonly WidgetRegistry $registry) {}
|
||||
|
||||
/**
|
||||
* @param array<int|string, mixed>|null $blocks gespeicherte Bausteine (Altformat oder Hülle)
|
||||
*/
|
||||
public function renderAll(?array $blocks, RenderContext $context): HtmlString
|
||||
{
|
||||
$html = '';
|
||||
$position = 0;
|
||||
|
||||
foreach (array_values($blocks ?? []) as $block) {
|
||||
if (! is_array($block)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$widget = $this->registry->upcast($block);
|
||||
|
||||
if ($widget === null) {
|
||||
if ($context->preview) {
|
||||
$html .= '<section class="block widget-unknown"><p class="preview-note">Unbekannter Baustein „'.e((string) ($block['type'] ?? '')).'“ wird öffentlich nicht angezeigt.</p></section>';
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$rendered = $this->renderWidget($widget, $context, $position === 0);
|
||||
|
||||
if ($rendered !== '') {
|
||||
$html .= $rendered;
|
||||
$position++;
|
||||
}
|
||||
}
|
||||
|
||||
return new HtmlString($html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendert eine Instanz samt Abschnittshülle. Liefert '' wenn das Widget nichts darzustellen hat.
|
||||
*
|
||||
* @param array<string, mixed> $widget aktuelle Hülle
|
||||
*/
|
||||
public function renderWidget(array $widget, RenderContext $context, bool $first = false): string
|
||||
{
|
||||
$type = $this->registry->get($widget['type']);
|
||||
|
||||
$inner = trim(view($type->view(), [
|
||||
'widget' => $widget,
|
||||
'data' => $widget['data'],
|
||||
'refs' => $widget['refs'],
|
||||
'variant' => $widget['variant'],
|
||||
'settings' => $widget['settings'],
|
||||
'first' => $first,
|
||||
'context' => $context,
|
||||
] + $type->resolve($widget, $context))->render());
|
||||
|
||||
if ($inner === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$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.'>'
|
||||
.$inner
|
||||
.'</section>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Cms\Widgets;
|
||||
|
||||
use Filament\Forms\Components\Field;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Components\Group;
|
||||
|
||||
/**
|
||||
* Vertrag einer Widget-Art (Website-CMS-Zielarchitektur 5.3, ADR-30).
|
||||
*
|
||||
* Eine Instanz wird als Hülle gespeichert:
|
||||
* {id, type, v, variant, settings, data, refs}
|
||||
*
|
||||
* - data: redaktionelle Inhalte dieser Instanz
|
||||
* - refs: Verweise auf Fachobjekte oder Medien, nur Kennungen
|
||||
* - settings: Aufzählungswerte aus settings(), keine freien Werte
|
||||
*
|
||||
* Eine neue Widget-Art ist eine Unterklasse und ein Eintrag in config/cms.php.
|
||||
* Der Seiteneditor und die Darstellung brauchen keine Sonderbehandlung.
|
||||
*/
|
||||
abstract class WidgetType
|
||||
{
|
||||
/** Stabile Typkennung; ändert sich nie, weil sie in Revisionen gespeichert ist. */
|
||||
abstract public function key(): string;
|
||||
|
||||
abstract public function label(): string;
|
||||
|
||||
abstract public function description(): string;
|
||||
|
||||
/** Aktuelle Schemaversion. Ältere Instanzen werden beim Lesen über upgrade() angehoben. */
|
||||
public function version(): int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Heroicon-Name für Auswahl und Liste im Editor. */
|
||||
public function icon(): string
|
||||
{
|
||||
return 'heroicon-o-square-3-stack-3d';
|
||||
}
|
||||
|
||||
/**
|
||||
* Symbolische Vorschau für die Widget-Auswahl: Liste von Flächen [x, y, b, h, ton] in einem 60×36-Raster.
|
||||
* Ton: 'ink', 'accent', 'line', 'image'. Kein redaktioneller Inhalt.
|
||||
*
|
||||
* @return list<array{0: int, 1: int, 2: int, 3: int, 4: string}>
|
||||
*/
|
||||
public function schematic(): array
|
||||
{
|
||||
return [[4, 6, 52, 4, 'ink'], [4, 14, 40, 3, 'line'], [4, 20, 44, 3, 'line'], [4, 26, 30, 3, 'line']];
|
||||
}
|
||||
|
||||
/**
|
||||
* Freigegebene Darstellungsvarianten: Kennung => Bezeichnung. Die erste ist die Vorgabe.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function variants(): array
|
||||
{
|
||||
return ['standard' => 'Standard'];
|
||||
}
|
||||
|
||||
public function defaultVariant(): string
|
||||
{
|
||||
return (string) array_key_first($this->variants());
|
||||
}
|
||||
|
||||
/**
|
||||
* Zulässige Einstellungen: Schlüssel => [Wert => Bezeichnung]. Keine freien CSS-Klassen.
|
||||
*
|
||||
* @return array<string, array<string, string>>
|
||||
*/
|
||||
public function settings(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüfregeln für data. Schlüssel relativ zu data (zum Beispiel 'heading', 'items.*.title').
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
abstract public function dataRules(): array;
|
||||
|
||||
/**
|
||||
* Prüfregeln für refs, relativ zu refs.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function refRules(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Formularfelder für data. Sie werden im Editor unter dem Zustandspfad 'data' eingehängt.
|
||||
*
|
||||
* @return list<Component|Field>
|
||||
*/
|
||||
abstract public function dataFields(): array;
|
||||
|
||||
/**
|
||||
* Formularfelder für refs, eingehängt unter 'refs'.
|
||||
*
|
||||
* @return list<Component|Field>
|
||||
*/
|
||||
public function refFields(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Anordnung der Felder im Bearbeitungsdialog. Vorgabe: Inhalte, dann Verweise.
|
||||
* Eine Art kann die Reihenfolge ändern, solange Felder unter 'data' beziehungsweise 'refs' bleiben.
|
||||
*
|
||||
* @return list<Component>
|
||||
*/
|
||||
public function editorSchema(): array
|
||||
{
|
||||
$schema = [];
|
||||
|
||||
if ($this->dataFields() !== []) {
|
||||
$schema[] = Group::make($this->dataFields())->statePath('data');
|
||||
}
|
||||
|
||||
if ($this->refFields() !== []) {
|
||||
$schema[] = Group::make($this->refFields())->statePath('refs');
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/** Blade-Ansicht. Sie dient öffentlicher Seite, ganzseitiger Vorschau und Blockvorschau gleichermaßen. */
|
||||
public function view(): string
|
||||
{
|
||||
return 'widgets.'.$this->key();
|
||||
}
|
||||
|
||||
/**
|
||||
* Übersetzt einen Altbaustein ohne Hülle (Bestand vor der Registry) in data/refs/variant der Version 1.
|
||||
*
|
||||
* @param array<string, mixed> $legacy
|
||||
* @return array{data: array<string, mixed>, refs: array<string, mixed>, variant?: string}
|
||||
*/
|
||||
public function fromLegacy(array $legacy): array
|
||||
{
|
||||
unset($legacy['type']);
|
||||
|
||||
return ['data' => $legacy, 'refs' => []];
|
||||
}
|
||||
|
||||
/**
|
||||
* Hebt eine Instanz von Version $from auf $from + 1. Alte Revisionen bleiben gespeichert, wie sie sind.
|
||||
*
|
||||
* @param array<string, mixed> $widget
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function upgrade(array $widget, int $from): array
|
||||
{
|
||||
throw new \LogicException(sprintf('Widget %s kennt keinen Schritt von Version %d.', $this->key(), $from));
|
||||
}
|
||||
|
||||
/**
|
||||
* Bereinigt geprüfte Inhalte vor dem Speichern (Adressen, formatierter Text, Bildauswahl).
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
* @param array<string, mixed> $refs
|
||||
* @return array{0: array<string, mixed>, 1: array<string, mixed>}
|
||||
*/
|
||||
public function clean(array $data, array $refs, WidgetErrors $errors): array
|
||||
{
|
||||
return [$data, $refs];
|
||||
}
|
||||
|
||||
/**
|
||||
* Löst Verweise für die Darstellung auf und liefert zusätzliche Ansichtsvariablen.
|
||||
*
|
||||
* @param array<string, mixed> $widget
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function resolve(array $widget, RenderContext $context): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Öffentliche Medienpfade dieser Instanz (für Veröffentlichung und Verwendungsnachweis).
|
||||
*
|
||||
* @param array<string, mixed> $widget
|
||||
* @return list<string>
|
||||
*/
|
||||
public function mediaPaths(array $widget): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Kurze Inhaltszusammenfassung für die Abschnittsliste im Editor.
|
||||
*
|
||||
* @param array<string, mixed> $widget
|
||||
*/
|
||||
public function summary(array $widget): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Titel, den eine Seite aus diesem Widget übernehmen kann, wenn kein SEO-Titel gesetzt ist.
|
||||
*
|
||||
* @param array<string, mixed> $widget
|
||||
*/
|
||||
public function pageTitle(array $widget): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user