Loheide-eu-mitarbeiterplatt.../app/Support/Navigation.php
Friederich Loheide 28ef1e4a20 Plugin-System; Neuigkeiten und Termine als mitgelieferte Plugins
- Plugins nach WordPress-Prinzip: plugin.json-Manifest mit Versions- und
  Abhängigkeitsprüfung, eigenes PSR-4-Autoloading, register()/boot(),
  activate()/deactivate()/uninstall(), Migrationen, Routen und Views je Plugin
- plugins-core/ (mitgeliefert, aktiv bis zur Deaktivierung) und plugins/
  (Kunden-Plugins, geschützt vor Updates, inaktiv bis zur Aktivierung)
- Zustand in storage/app/plugins.json – Laden ohne Datenbankabfrage
- Wiederherstellungsmodus: Ausnahmen und Fatal Errors beim Laden
  deaktivieren das Plugin, das Portal bleibt erreichbar
- Hooks (Actions/Filter mit Prioritäten) und Registries für Navigation,
  Startseiten-Kacheln, Rechte und Admin-Seiten (Filament-Discovery)
- Admin-Seite „Plugins“: aktivieren, deaktivieren, per ZIP installieren
  (ZIP-Slip-Schutz), löschen mit oder ohne Daten; abschaltbar per
  INHAUS_DISALLOW_FILE_MODS
- Startseite komplett aus Kacheln; Plugin-Seiten als „slug::Seite“
- Version 0.3.0

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

57 lines
1.9 KiB
PHP

<?php
namespace App\Support;
use App\Models\User;
use App\Plugins\Hooks;
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);
*/
class Navigation
{
/** @var array<string, array{label: string, href: string, active: list<string>, sort: int, ability: string|null}> */
private array $items = [];
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
*/
public function add(string $key, string $label, string $href, string|array $active = [], int $sort = 50, ?string $ability = null): void
{
$this->items[$key] = ['label' => $label, 'href' => $href, 'active' => (array) $active, 'sort' => $sort, 'ability' => $ability];
}
public function remove(string $key): void
{
unset($this->items[$key]);
}
/**
* @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))
->sortBy('sort')
->map(fn (array $item, string $key) => [
'key' => $key,
'label' => $item['label'],
'href' => $item['href'],
'active' => $item['active'] !== [] && $request->routeIs(...$item['active']),
])
->values()
->all();
return Hooks::apply('navigation.items', $items, $request, $user);
}
}