- 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>
72 lines
2.5 KiB
PHP
72 lines
2.5 KiB
PHP
<?php
|
||
|
||
namespace App\Dashboard;
|
||
|
||
use App\Models\User;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Support\Facades\Log;
|
||
use Throwable;
|
||
|
||
/**
|
||
* Kacheln der Startseite als Registry.
|
||
*
|
||
* Bereiche (siehe resources/js/pages/Dashboard.vue):
|
||
* hero – groß links oben (z. B. Slider) feed – neben hero
|
||
* main – volle Breite der linken Spalte aside – rechte Spalte
|
||
*
|
||
* Die Props-Funktion liefert die Daten der Kachel oder null, wenn sie für
|
||
* diese Person nichts anzuzeigen hat.
|
||
*/
|
||
class Widgets
|
||
{
|
||
public const AREAS = ['hero', 'feed', 'main', 'aside'];
|
||
|
||
/** @var array<string, array{component: string, area: string, sort: int, mobileSort: int, props: callable}> */
|
||
private array $widgets = [];
|
||
|
||
/**
|
||
* @param string $component Vue-Komponente, z. B. „core::QuickLinks“ oder „news::Hero“
|
||
* @param callable(User, Request): (array<string, mixed>|null) $props
|
||
* @param int|null $mobileSort Reihenfolge in der einspaltigen Mobilansicht (Standard: nach Bereich)
|
||
*/
|
||
public function add(string $key, string $component, string $area, int $sort, callable $props, ?int $mobileSort = null): void
|
||
{
|
||
if (! in_array($area, self::AREAS, true)) {
|
||
throw new \InvalidArgumentException("Unbekannter Bereich „{$area}“ für Kachel {$key}.");
|
||
}
|
||
|
||
$mobileSort ??= ['hero' => 10, 'feed' => 20, 'aside' => 30, 'main' => 50][$area] + $sort;
|
||
|
||
$this->widgets[$key] = compact('component', 'area', 'sort', 'mobileSort', 'props');
|
||
}
|
||
|
||
public function remove(string $key): void
|
||
{
|
||
unset($this->widgets[$key]);
|
||
}
|
||
|
||
/**
|
||
* @return list<array{key: string, component: string, area: string, mobileSort: int, props: array<string, mixed>}>
|
||
*/
|
||
public function resolve(User $user, Request $request): array
|
||
{
|
||
$result = [];
|
||
|
||
foreach (collect($this->widgets)->sortBy('sort') as $key => $widget) {
|
||
try {
|
||
$props = ($widget['props'])($user, $request);
|
||
} catch (Throwable $e) {
|
||
// Eine fehlerhafte Kachel darf die Startseite nicht lahmlegen.
|
||
Log::error("Startseiten-Kachel {$key} fehlgeschlagen: ".$e->getMessage(), ['exception' => $e]);
|
||
|
||
continue;
|
||
}
|
||
|
||
if ($props !== null) {
|
||
$result[] = ['key' => $key, 'component' => $widget['component'], 'area' => $widget['area'], 'mobileSort' => $widget['mobileSort'], 'props' => $props];
|
||
}
|
||
}
|
||
|
||
return $result;
|
||
}
|
||
}
|