". Register new sections in config/themes.php. */ abstract class Section { abstract public static function key(): string; abstract public static function label(): string; /** * Heroicon name shown in the page builder. */ public static function icon(): string { return 'heroicon-o-square-3-stack-3d'; } /** * Admin fields of the section (builder block schema). Field names are keys of $data in data(). * * @return list */ public static function schema(): array { return []; } /** * Variables for the view. * * @param array $data what the admin entered * @return array */ abstract public function data(Theme $theme, array $data): array; public function view(): string { return 'theme::sections.'.static::key(); } /** * Sanitised HTML of a rich text field. */ protected function html(?string $value): ?HtmlString { return filled($value) ? new HtmlString(RichContentRenderer::make($value)->toHtml()) : null; } /** * @param list|null $ids * @return Collection */ protected function photos(?array $ids): Collection { if (blank($ids)) { return new Collection; } $photos = Photo::query()->published()->whereKey($ids)->with('media')->get()->keyBy('id'); return new Collection(array_values(array_filter(array_map(fn ($id) => $photos->get((int) $id), $ids)))); } protected function pageUrl(?string $slug): ?string { if (blank($slug)) { return null; } return $slug === Page::HOME ? route('home') : route('page', ['slug' => $slug]); } /** * Select field listing the website photos. */ protected static function photoSelect(string $name, string $label, bool $multiple = false): Select { return Select::make($name) ->label($label) ->options(fn (): array => Photo::query()->orderBy('category')->orderBy('sort_order')->pluck('alt_text', 'id')->all()) ->multiple($multiple) ->searchable(); } /** * Select field listing the pages of the site, for links. */ protected static function pageSelect(string $name, string $label): Select { return Select::make($name) ->label($label) ->options(fn (): array => Page::query()->orderBy('sort_order')->pluck('title', 'slug')->all()) ->searchable(); } }