Files
fewo-stommer/app/Themes/Sections/Section.php
T
Lars StommerandClaude Opus 5.5 66e82d61f5 Theme-System mit Basis-Theme Ostsee-Licht, Bausteinen und saisonalen Erscheinungsbildern
- Sites (Domain, Theme, Farben; mehrfähig für weitere Vermieter), Seiten aus Bausteinen mit Menüs, Erscheinungsbilder mit jährlichem Zeitplan, Priorität und signierter Vorschau
- Theme-Kern (app/Themes): Manifest, Registry, Vererbung (Child-Themes), Token-Farben als CSS-Variablen, Bausteinkatalog als Registry (config/themes.php)
- 15 Bausteine: Titelbereich mit Suche, Eckdaten, Text mit Bildern, Galerie, Ausstattung, Lage, Preise, Angebote, Kalender & Anfrage, Bewertungen, Gastgeber, FAQ, Abschluss, Kontakt, Fließtext
- Theme Ostsee-Licht: Layout, Kopf/Fuß, Banner, mobile Buchungsleiste, Lightbox, selbst gehostete Schriften, Reduced Motion
- Seiten Start, Wohnung, Kühlungsborn, Preise & Buchung, Kontakt, Impressum, Datenschutz; Sitemap, robots.txt, JSON-LD
- Admin: Seiten-Baukasten, Erscheinungsbilder, Websites
- Dokumentation docs/THEMES.md inkl. Übergabe für die Design-Sitzung

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 15:04:21 +02:00

110 lines
3.0 KiB
PHP

<?php
namespace App\Themes\Sections;
use App\Models\Page;
use App\Models\Photo;
use App\Themes\Theme;
use Filament\Forms\Components\RichEditor\RichContentRenderer;
use Filament\Forms\Components\Select;
use Filament\Schemas\Components\Component;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\HtmlString;
/**
* A building block of pages. A section prepares data; how it looks is up to the theme's
* view "theme::sections.<key>". 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<Component>
*/
public static function schema(): array
{
return [];
}
/**
* Variables for the view.
*
* @param array<string, mixed> $data what the admin entered
* @return array<string, mixed>
*/
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<int|string>|null $ids
* @return Collection<int, Photo>
*/
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();
}
}