Loheide-eu-mitarbeiterplatt.../app/Support/Navigation.php
Friederich Loheide f3987e8386
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m40s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s
Phase 4: Seiten mit Pagebuilder, Redaktion und Freigaben
- Seiten-Plugin: Seitenbaum mit Adressen, Seitennavigation, Brotkrumen und
  optional Hauptnavigation; Sichtbarkeit vererbt sich auf Unterseiten
- Pagebuilder (Block-Registry im Kern, Plugins tragen Blöcke bei): Abschnitt,
  Spalten, Tabs, Akkordeon, Box, Überschrift, Text (TipTap), Zitat,
  Schaltflächen, Symbolliste, Tabelle, Trennlinie, Abstand, Bild, Galerie,
  Video (erst nach Klick), Titelbild, Ansprechpartner, Downloads, Unterseiten,
  Neuigkeiten, Termine; Sichtbarkeit je Block; Bereinigung beim Speichern
- Editor im Portal: Ziehen und Ablegen, Autospeichern als Entwurf,
  Rückgängig, Gerätevorschau, Versionen, Zeitsteuerung, Bearbeitungssperre,
  Freigabe anfordern
- Rechte „inkl. Unterseiten“ werden im Rechte-Cache aufgelöst
- Neuigkeiten: Schreiben im Portal, Freigabe-Workflow mit Benachrichtigungen
- Bereich „Redaktion“, Benachrichtigungen im Portal
- storage/.migrations-fingerprint nicht mehr ausliefern

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 08:52:19 +00:00

84 lines
3.1 KiB
PHP

<?php
namespace App\Support;
use App\Models\User;
use App\Plugins\Hooks;
use Closure;
use Illuminate\Http\Request;
/**
* Hauptnavigation des Portals als Registry: Kern und Plugins tragen Einträge ein.
*
* app(Navigation::class)->add('news', 'Neuigkeiten', '/neuigkeiten', active: 'news.*', sort: 20);
*
* Dynamische Einträge (z. B. Seiten aus dem Seitenbaum) liefert ein Provider:
*
* app(Navigation::class)->provider('pages', fn (Request $request, ?User $user) => [
* ['key' => 'page-3', 'label' => 'MAV', 'href' => '/seiten/mav', 'active' => true, 'sort' => 40],
* ]);
*/
class Navigation
{
/** @var array<string, array{label: string, href: string, active: list<string>, sort: int, ability: string|null, visible: Closure|null}> */
private array $items = [];
/** @var array<string, Closure> */
private array $providers = [];
public function __construct()
{
$this->add('home', 'Startseite', '/', active: 'dashboard', sort: 0);
$this->add('people', 'Personen', '/personen', active: 'people.*', sort: 90);
}
/**
* @param string|list<string> $active Routennamen (mit *), bei denen der Eintrag aktiv ist
* @param (Closure(User): bool)|null $visible zusätzliche Bedingung je Person
*/
public function add(string $key, string $label, string $href, string|array $active = [], int $sort = 50, ?string $ability = null, ?Closure $visible = null): void
{
$this->items[$key] = ['label' => $label, 'href' => $href, 'active' => (array) $active, 'sort' => $sort, 'ability' => $ability, 'visible' => $visible];
}
public function remove(string $key): void
{
unset($this->items[$key], $this->providers[$key]);
}
/**
* @param Closure(Request, User|null): list<array{key: string, label: string, href: string, active: bool, sort: int}> $items
*/
public function provider(string $key, Closure $items): void
{
$this->providers[$key] = $items;
}
/**
* @return list<array{key: string, label: string, href: string, active: bool}>
*/
public function items(Request $request, ?User $user = null): array
{
$items = collect($this->items)
->filter(fn (array $item) => $item['ability'] === null || ($user?->can($item['ability']) ?? false))
->filter(fn (array $item) => $item['visible'] === null || ($user !== null && ($item['visible'])($user)))
->map(fn (array $item, string $key) => [
'key' => $key,
'label' => $item['label'],
'href' => $item['href'],
'active' => $item['active'] !== [] && $request->routeIs(...$item['active']),
'sort' => $item['sort'],
]);
foreach ($this->providers as $provider) {
$items = $items->merge($provider($request, $user));
}
$items = $items->sortBy('sort')
->map(fn (array $item) => ['key' => $item['key'], 'label' => $item['label'], 'href' => $item['href'], 'active' => (bool) $item['active']])
->values()
->all();
return Hooks::apply('navigation.items', $items, $request, $user);
}
}