Lass Menüeinträge auf eine Sprungmarke der Zielseite zeigen

Zweiter Schritt in „Ziel ändern“, neue Spalte navigation_items.anchor (nullable, abwärtskompatibel).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-27 07:05:22 +01:00
1 parent 6b43fbb7d1
commit 04a9a4f83f
5 files changed
+274 -7

No files matched your search

+67 -4
View File
@@ -2,9 +2,11 @@
namespace App\Filament\Pages;
use App\Domain\Cms\LinkTargets;
use App\Domain\Cms\NavigationItem;
use App\Domain\Cms\Page as CmsPage;
use App\Domain\Cms\PageService;
use App\Domain\Cms\Sections\PageSections;
use App\Domain\Cms\Widgets\Support\SafeUrl;
use App\Filament\Resources\Pages\PageResource;
use App\Filament\Support\Bestand;
@@ -74,7 +76,7 @@ class Webpraesenz extends Page
/** Ausgewählter Eintrag (Schlüssel „e{id}“ oder „n{zähler}“ für neue Einträge). */
public ?string $auswahl = null;
/** @var array<string, array{id: ?int, label: string, page_id: ?int, url: string, placement: string, parent: ?string, is_visible: bool}> */
/** @var array<string, array{id: ?int, label: string, page_id: ?int, url: string, anchor: string, placement: string, parent: ?string, is_visible: bool}> */
public array $eintraege = [];
/** Globale Reihenfolge der Schlüssel; entspricht sort_order. @var list<string> */
@@ -103,6 +105,9 @@ class Webpraesenz extends Page
/** Eintrag, dessen Ziel gerade gewählt wird. */
public ?string $zielwahl = null;
/** Zweiter Schritt der Zielwahl: gewählte Seite, deren Sprungmarke noch zu wählen ist. */
public ?int $zielSeite = null;
public string $zielSuche = '';
public static function canAccess(): bool
@@ -327,6 +332,7 @@ public function ladeMenues(): void
'label' => (string) $item->label,
'page_id' => $item->page_id,
'url' => (string) ($item->url ?? ''),
'anchor' => (string) ($item->anchor ?? ''),
'placement' => (string) $item->placement,
'parent' => $item->parent_id !== null ? 'e'.$item->parent_id : null,
'is_visible' => (bool) $item->is_visible,
@@ -364,6 +370,7 @@ private function bereichsStaende(): array
trim($e['label']),
$e['page_id'] !== null ? (int) $e['page_id'] : null,
trim($e['url']),
trim($e['anchor'] ?? ''),
(bool) $e['is_visible'],
$this->elternVon($k),
];
@@ -562,6 +569,7 @@ public function eintragHinzufuegen(): void
'label' => '',
'page_id' => null,
'url' => '',
'anchor' => '',
'placement' => $this->menue,
'parent' => null,
'is_visible' => true,
@@ -595,7 +603,7 @@ public function updatedEintraege(mixed $value, string $pfad): void
match ($feld) {
'placement' => $this->bereichGeaendert($k),
'parent' => $this->elternGeaendert($k),
'page_id' => $this->eintraege[$k]['page_id'] = blank($value) ? null : (int) $value,
'page_id' => $this->seiteGeaendert($k, $value),
'is_visible' => $this->eintraege[$k]['is_visible'] = (bool) $value,
default => null,
};
@@ -673,10 +681,18 @@ private function ansEnde(string $k): void
$this->folge = [...array_values(array_filter($this->folge, fn (string $x): bool => $x !== $k)), $k];
}
/** Eine andere Zielseite hat eigene Sprungmarken: Die bisherige Marke entfällt. */
private function seiteGeaendert(string $k, mixed $value): void
{
$this->eintraege[$k]['page_id'] = blank($value) ? null : (int) $value;
$this->eintraege[$k]['anchor'] = '';
}
public function zielAdresseNutzen(string $k): void
{
if (isset($this->eintraege[$k])) {
$this->eintraege[$k]['page_id'] = null;
$this->eintraege[$k]['anchor'] = '';
$this->js("requestAnimationFrame(() => document.getElementById('menue-adresse')?.focus())");
}
}
@@ -692,6 +708,7 @@ public function oeffneZielwahl(string $k): void
public function schliesseZielwahl(): void
{
$this->zielwahl = null;
$this->zielSeite = null;
}
public function waehleZiel(int $seiteId): void
@@ -702,8 +719,48 @@ public function waehleZiel(int $seiteId): void
$this->eintraege[$this->zielwahl]['page_id'] = $seiteId;
$this->eintraege[$this->zielwahl]['url'] = '';
$this->eintraege[$this->zielwahl]['anchor'] = '';
$this->resetErrorBag("eintraege.{$this->zielwahl}.url");
$this->zielwahl = null;
// Hat die Seite Sprungmarken, folgt als zweiter Schritt die Wahl der Marke; sonst ist die Auswahl fertig.
if ($this->zielMarken($seiteId) !== []) {
$this->zielSeite = $seiteId;
return;
}
$this->schliesseZielwahl();
}
/**
* Zweiter Schritt von „Ziel ändern“: Sprungmarke der gewählten Seite übernehmen (leer = Seitenanfang).
*/
public function waehleMarke(?string $marke = null): void
{
if ($this->zielwahl === null || $this->zielSeite === null || ! isset($this->eintraege[$this->zielwahl])) {
return;
}
$marke = filled($marke) ? $marke : null;
if ($marke !== null && ! in_array($marke, array_column($this->zielMarken($this->zielSeite), 'anchor'), true)) {
return;
}
$this->eintraege[$this->zielwahl]['anchor'] = $marke ?? '';
$this->schliesseZielwahl();
}
/**
* Sprungmarken einer Seite für den zweiten Schritt.
*
* @return list<array{anchor: string, label: string, hidden: bool, published: bool}>
*/
public function zielMarken(int $seiteId): array
{
$seite = $this->seitenCache()->get($seiteId);
return $seite === null ? [] : app(LinkTargets::class)->anchorsForPage($seite);
}
/**
@@ -755,7 +812,7 @@ public function zielVon(string $k): array
return $seite === null
? ['art' => 'fehlt', 'titel' => null, 'pfad' => null, 'zustand' => ['label' => 'Zielseite nicht mehr vorhanden', 'ton' => 'achtung'], 'seite' => null]
: ['art' => 'seite', 'titel' => $seite->latestRevision?->contentTitle() ?: $seite->path, 'pfad' => $seite->path, 'zustand' => $this->seitenZustand($seite), 'seite' => $seite];
: ['art' => 'seite', 'titel' => $seite->latestRevision?->contentTitle() ?: $seite->path, 'pfad' => $seite->path.(trim($e['anchor'] ?? '') !== '' ? '#'.trim($e['anchor']) : ''), 'zustand' => $this->seitenZustand($seite), 'seite' => $seite];
}
if (trim($e['url']) !== '') {
@@ -919,6 +976,7 @@ private function pruefen(): array
|| $alt->label !== $e['label']
|| $alt->page_id !== ($e['page_id'] !== null ? (int) $e['page_id'] : null)
|| (string) ($alt->url ?? '') !== $e['url']
|| (string) ($alt->anchor ?? '') !== trim($e['anchor'] ?? '')
|| $alt->placement !== $e['placement']
|| ($alt->parent_id !== null ? 'e'.$alt->parent_id : null) !== $this->elternVon($k)
|| (bool) $alt->is_visible !== (bool) $e['is_visible']
@@ -936,16 +994,19 @@ private function pruefen(): array
'placement' => $e['placement'],
'page_id' => $e['page_id'],
'url' => trim($e['url']) === '' ? null : trim($e['url']),
'anchor' => trim($e['anchor'] ?? '') === '' ? null : trim($e['anchor']),
], [
'label' => ['required', 'string', 'max:80'],
'placement' => ['required', 'in:'.implode(',', array_keys(self::BEREICHE))],
'page_id' => ['nullable', 'integer', 'exists:pages,id'],
'url' => ['nullable', 'string', 'max:500', SafeUrl::rule()],
'anchor' => ['nullable', 'string', 'max:'.PageSections::MAX_ANCHOR, 'regex:'.PageSections::ANCHOR_PATTERN],
], [
'label.required' => 'Bitte einen Menütext eingeben.',
'label.max' => 'Der Menütext hat höchstens 80 Zeichen.',
'url.max' => 'Die Adresse hat höchstens 500 Zeichen.',
'page_id.exists' => 'Diese Seite gibt es nicht mehr.',
'anchor.regex' => 'Die Sprungmarke ist ungültig. Bitte über „Ziel ändern“ eine vorhandene wählen.',
]);
$meldungen = $validator->errors()->toArray();
@@ -1044,6 +1105,8 @@ private function schreiben(array $geaendert): array
'label' => trim($e['label']),
'page_id' => $e['page_id'] !== null ? (int) $e['page_id'] : null,
'url' => trim($e['url']) === '' ? null : trim($e['url']),
// Eine Sprungmarke gehört zur Zielseite; ohne Seite (freie Adresse) entfällt sie.
'anchor' => $e['page_id'] !== null && trim($e['anchor'] ?? '') !== '' ? trim($e['anchor']) : null,
'placement' => $e['placement'],
'parent_id' => $eltern !== null ? ($ids[$eltern] ?? $this->eintraege[$eltern]['id']) : null,
'is_visible' => (bool) $e['is_visible'],