Symbole für alle Hauptpunkte im automatischen Menü (0.40.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 8m25s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 8m46s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 11m36s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 11m31s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 11m34s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 12m12s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 12m14s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 46s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 11m18s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m15s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 8m25s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 8m46s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 11m36s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 11m31s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 11m34s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 12m12s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 12m14s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 46s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 11m18s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m15s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
a704d12d2a
commit
8a9399b6a5
21 changed files with 102 additions and 29 deletions
|
|
@ -11,7 +11,7 @@ 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);
|
||||
* app(Navigation::class)->add('news', 'Neuigkeiten', '/neuigkeiten', active: 'news.*', sort: 20, icon: 'newspaper');
|
||||
*
|
||||
* Dynamische Einträge (z. B. Seiten aus dem Seitenbaum) liefert ein Provider:
|
||||
*
|
||||
|
|
@ -25,7 +25,7 @@ use Illuminate\Http\Request;
|
|||
*/
|
||||
class Navigation
|
||||
{
|
||||
/** @var array<string, array{label: string, href: string, active: list<string>, sort: int, ability: string|null, visible: Closure|null}> */
|
||||
/** @var array<string, array{label: string, href: string, active: list<string>, sort: int, ability: string|null, visible: Closure|null, icon: string|null}> */
|
||||
private array $items = [];
|
||||
|
||||
/** @var array<string, Closure> */
|
||||
|
|
@ -33,6 +33,30 @@ class Navigation
|
|||
|
||||
public const MENU_SETTING = 'navigation.menu';
|
||||
|
||||
/** Symbole im automatischen Menü, wenn ein Bereich keines mitgibt (auch separat installierte Plugins) */
|
||||
public const DEFAULT_ICONS = [
|
||||
'home' => 'house',
|
||||
'people' => 'contact',
|
||||
'editorial' => 'pen-line',
|
||||
'news' => 'newspaper',
|
||||
'events' => 'calendar-days',
|
||||
'downloads' => 'folder-down',
|
||||
'qm' => 'shield-check',
|
||||
'gemeinsam' => 'handshake',
|
||||
'speiseplan' => 'utensils',
|
||||
'it-service' => 'headset',
|
||||
'glossar' => 'book-a',
|
||||
'stellen' => 'briefcase',
|
||||
'umfragen' => 'vote',
|
||||
'ideen' => 'lightbulb',
|
||||
'forms' => 'clipboard-list',
|
||||
'chat' => 'message-circle',
|
||||
'gruppen' => 'users-round',
|
||||
'kleinanzeigen' => 'shopping-bag',
|
||||
];
|
||||
|
||||
public const FALLBACK_ICON = 'layout-grid';
|
||||
|
||||
/** @var array<string, array{label: string, options: Closure, resolve: Closure}> */
|
||||
private array $sources = [];
|
||||
|
||||
|
|
@ -41,17 +65,31 @@ class Navigation
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->add('home', 'Startseite', '/', active: 'dashboard', sort: 0);
|
||||
$this->add('people', 'Personen', '/personen', active: 'people.*', sort: 90);
|
||||
$this->add('home', 'Startseite', '/', active: 'dashboard', sort: 0, icon: 'house');
|
||||
$this->add('people', 'Personen', '/personen', active: 'people.*', sort: 90, icon: 'contact');
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
/**
|
||||
* @param string|null $icon Lucide-Symbol im automatischen Menü (z. B. „calendar-days“)
|
||||
*/
|
||||
public function add(string $key, string $label, string $href, string|array $active = [], int $sort = 50, ?string $ability = null, ?Closure $visible = null, ?string $icon = null): void
|
||||
{
|
||||
$this->items[$key] = ['label' => $label, 'href' => $href, 'active' => (array) $active, 'sort' => $sort, 'ability' => $ability, 'visible' => $visible];
|
||||
$this->items[$key] = ['label' => $label, 'href' => $href, 'active' => (array) $active, 'sort' => $sort, 'ability' => $ability, 'visible' => $visible, 'icon' => $icon];
|
||||
}
|
||||
|
||||
/**
|
||||
* Symbol eines Bereichs: angegeben, sonst ein passender Standard (auch für Plugins, die
|
||||
* noch kein Symbol mitgeben), sonst ein neutrales.
|
||||
*/
|
||||
public function iconFor(string $key): string
|
||||
{
|
||||
$icon = $this->items[$key]['icon'] ?? self::DEFAULT_ICONS[$key] ?? null;
|
||||
|
||||
return Icons::has($icon) ? $icon : self::FALLBACK_ICON;
|
||||
}
|
||||
|
||||
public function remove(string $key): void
|
||||
|
|
@ -139,6 +177,7 @@ class Navigation
|
|||
'href' => $item['href'],
|
||||
'active' => $item['active'] !== [] && $request->routeIs(...$item['active']),
|
||||
'sort' => $item['sort'],
|
||||
'icon' => $this->iconFor($key),
|
||||
]);
|
||||
|
||||
foreach ($this->providers as $key => $provider) {
|
||||
|
|
@ -150,7 +189,8 @@ class Navigation
|
|||
}
|
||||
|
||||
return $items->sortBy('sort')
|
||||
->map(fn (array $item) => ['key' => $item['key'], 'label' => $item['label'], 'href' => $item['href'], 'active' => (bool) $item['active'], 'icon' => null, 'new_tab' => false, 'children' => []])
|
||||
// Jeder Hauptpunkt mit Symbol – Seiten aus der Hauptnavigation mit Seiten-Symbol
|
||||
->map(fn (array $item) => ['key' => $item['key'], 'label' => $item['label'], 'href' => $item['href'], 'active' => (bool) $item['active'], 'icon' => Icons::has($item['icon'] ?? null) ? $item['icon'] : 'file-text', 'new_tab' => false, 'children' => []])
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue