> */ public function all(): array { return collect(config('themes.sections')) ->mapWithKeys(fn (string $class): array => [$class::key() => $class]) ->all(); } public function get(string $key): ?Section { $class = $this->all()[$key] ?? null; return $class ? app($class) : null; } /** * @return list */ public function blocks(): array { return array_values(array_map( fn (string $class): Block => Block::make($class::key()) ->label($class::label()) ->icon($class::icon()) ->schema($class::schema()), $this->all(), )); } /** * Renders the stored sections of a page; unknown or failing types are skipped (and reported), * so a page never breaks because of one section. * * @param list}>|null $sections * @return list */ public function render(Theme $theme, ?array $sections): array { $views = []; foreach ($sections ?? [] as $index => $stored) { $section = $this->get($stored['type'] ?? ''); if ($section === null || ! ViewFactory::exists($section->view())) { continue; } $views[] = ViewFactory::make($section->view(), [ ...$section->data($theme, $stored['data'] ?? []), 'theme' => $theme, 'sectionId' => $section::key().'-'.$index, ]); } return $views; } }