Redaktion mit Bereichsleiste und Übersicht (0.42.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 6m51s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m48s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m16s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m21s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m30s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 9m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m49s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m37s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 44s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m8s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-27 18:38:44 +00:00
parent b1209a0d33
commit d5b7b1e0a8
146 changed files with 666 additions and 362 deletions

View file

@ -3,6 +3,8 @@
namespace App\Editorial;
use App\Models\User;
use App\Support\Icons;
use App\Support\Navigation;
use Closure;
use Illuminate\Support\Facades\Log;
use Throwable;
@ -17,6 +19,9 @@ class Editorial
/** @var array<string, array{label: string, component: string, sort: int, visible: Closure, props: Closure}> */
private array $sections = [];
/** @var array<string, array{icon: ?string, todo: ?Closure, create: ?Closure}> */
private array $meta = [];
/**
* @param Closure(User): bool $visible schnelle Rechteprüfung (ohne Abfragen)
* @param Closure(User): array<string, mixed> $props
@ -26,9 +31,93 @@ class Editorial
$this->sections[$key] = compact('label', 'component', 'sort', 'visible', 'props');
}
/**
* Zusatzangaben für die Navigation der Redaktion (ab 0.42.0):
*
* $editorial->meta('news', icon: 'newspaper',
* todo: fn (User $u) => ['count' => 3, 'label' => 'Beiträge warten auf Freigabe'], // oder null
* create: fn (User $u) => ['label' => 'Neuer Beitrag', 'href' => '/redaktion/neuigkeiten/neu']);
*
* „todo“ zählt nur, was jetzt Handlung braucht – es erscheint als Zahl in der Leiste und in der Übersicht.
*
* @param (Closure(User): (array{count: int, label: string}|null))|null $todo
* @param (Closure(User): (array{label: string, href: string}|null))|null $create
*/
public function meta(string $key, ?string $icon = null, ?Closure $todo = null, ?Closure $create = null): void
{
$this->meta[$key] = compact('icon', 'todo', 'create');
}
public function remove(string $key): void
{
unset($this->sections[$key]);
unset($this->sections[$key], $this->meta[$key]);
}
/**
* Bereiche für die Leiste: Bezeichnung, Symbol, offene Aufgaben – ohne die Listen selbst zu laden.
*
* @return list<array{key: string, label: string, icon: string, todo: array{count: int, label: string}|null, create: array{label: string, href: string}|null}>
*/
public function menu(User $user): array
{
$result = [];
foreach (collect($this->sections)->sortBy('sort') as $key => $section) {
if (! ($section['visible'])($user)) {
continue;
}
$meta = $this->meta[$key] ?? [];
$result[] = [
'key' => $key,
'label' => $section['label'],
'icon' => $this->icon($key, $meta['icon'] ?? null),
'todo' => $this->call($key, $meta['todo'] ?? null, $user, fn ($todo) => is_array($todo) && ($todo['count'] ?? 0) > 0),
'create' => $this->call($key, $meta['create'] ?? null, $user, fn ($create) => is_array($create) && filled($create['href'] ?? null)),
];
}
return $result;
}
/**
* Ein einzelner Bereich mit seinen Daten – null, wenn es ihn nicht gibt oder er nicht erlaubt ist.
*
* @return array{key: string, label: string, component: string, props: array<string, mixed>}|null
*/
public function section(string $key, User $user): ?array
{
$section = $this->sections[$key] ?? null;
if (! $section || ! ($section['visible'])($user)) {
return null;
}
return ['key' => $key, 'label' => $section['label'], 'component' => $section['component'], 'props' => ($section['props'])($user)];
}
private function icon(string $key, ?string $icon): string
{
$fallback = Navigation::DEFAULT_ICONS[explode('.', $key)[0]] ?? Navigation::FALLBACK_ICON;
return Icons::has($icon) ? $icon : $fallback;
}
private function call(string $key, ?Closure $callback, User $user, Closure $valid): ?array
{
if (! $callback) {
return null;
}
try {
$value = $callback($user);
return $valid($value) ? $value : null;
} catch (Throwable $e) {
Log::error("Redaktionsbereich {$key}: ".$e->getMessage(), ['exception' => $e]);
return null;
}
}
/**