*/ private array $widgets = []; /** * @param string $component Vue-Komponente, z. B. „core::QuickLinks“ oder „news::Hero“ * @param callable(User, Request): (array|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}> */ 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; } }