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>
This commit is contained in:
Lars StommerandClaude Opus 5.5 committed 2026-10-22 15:04:21 +02:00
1 parent f2c48013ad
commit 66e82d61f5
119 files changed
+4066 -481

No files matched your search

+71
View File
@@ -0,0 +1,71 @@
<?php
namespace App\Themes;
use App\Themes\Sections\Section;
use Filament\Forms\Components\Builder\Block;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\View as ViewFactory;
/**
* The section catalogue from config/themes.php: builder blocks for the admin and rendering for the website.
*/
class SectionRegistry
{
/**
* @return array<string, class-string<Section>>
*/
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<Block>
*/
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<array{type: string, data?: array<string, mixed>}>|null $sections
* @return list<View>
*/
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;
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace App\Themes\Sections;
use App\Themes\Theme;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
/**
* The equipment list grouped by room (Admin › Webseite › Ausstattung).
*/
class AmenitiesSection extends Section
{
public static function key(): string
{
return 'amenities';
}
public static function label(): string
{
return 'Ausstattung';
}
public static function icon(): string
{
return 'heroicon-o-list-bullet';
}
public static function schema(): array
{
return [
TextInput::make('heading')->label('Überschrift')->default('Ausstattung')->maxLength(120),
Toggle::make('highlights_only')->label('Nur Highlights zeigen'),
];
}
public function data(Theme $theme, array $data): array
{
$amenities = $theme->property()?->amenities()
->when($data['highlights_only'] ?? false, fn ($query) => $query->where('is_highlight', true))
->get() ?? collect();
return [
'heading' => $data['heading'] ?? 'Ausstattung',
'groups' => $amenities->groupBy(fn ($amenity): string => $amenity->area->getLabel()),
];
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace App\Themes\Sections;
use App\Themes\Theme;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
/**
* Availability calendar, live price and booking request (Livewire component App\Livewire\BookingRequest).
*/
class BookingSection extends Section
{
public static function key(): string
{
return 'booking';
}
public static function label(): string
{
return 'Kalender & Anfrage';
}
public static function icon(): string
{
return 'heroicon-o-calendar-days';
}
public static function schema(): array
{
return [
TextInput::make('heading')->label('Überschrift')->default('Preise & Buchung')->maxLength(120),
Textarea::make('text')->label('Text')->rows(2),
];
}
public function data(Theme $theme, array $data): array
{
return [
'heading' => $data['heading'] ?? null,
'text' => $data['text'] ?? null,
'property' => $theme->property(),
];
}
}
@@ -0,0 +1,51 @@
<?php
namespace App\Themes\Sections;
use App\Models\Photo;
use App\Themes\Theme;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
/**
* Closing invitation with photo and button; seasonal appearances may replace the texts.
*/
class CallToActionSection extends Section
{
public static function key(): string
{
return 'cta';
}
public static function label(): string
{
return 'Abschluss mit Aufruf';
}
public static function icon(): string
{
return 'heroicon-o-cursor-arrow-rays';
}
public static function schema(): array
{
return [
TextInput::make('title')->label('Überschrift')->required()->maxLength(160),
Textarea::make('text')->label('Text')->rows(2),
static::photoSelect('photo_id', 'Hintergrundfoto'),
TextInput::make('button_label')->label('Button-Text')->default('Belegung & Preise')->maxLength(60),
static::pageSelect('button_page', 'Button führt zu'),
];
}
public function data(Theme $theme, array $data): array
{
return [
'title' => $theme->text('cta.title', $data['title'] ?? null),
'text' => $theme->text('cta.text', $data['text'] ?? null),
'photo' => isset($data['photo_id']) ? Photo::find($data['photo_id']) : null,
'buttonLabel' => $data['button_label'] ?? 'Belegung & Preise',
'buttonUrl' => $this->pageUrl($data['button_page'] ?? null) ?? route('booking.create'),
];
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace App\Themes\Sections;
use App\Themes\Theme;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
/**
* Contact details of the landlord and the property address.
*/
class ContactSection extends Section
{
public static function key(): string
{
return 'contact';
}
public static function label(): string
{
return 'Kontakt';
}
public static function icon(): string
{
return 'heroicon-o-envelope';
}
public static function schema(): array
{
return [
TextInput::make('heading')->label('Überschrift')->default('Kontakt')->maxLength(120),
Textarea::make('text')->label('Text')->rows(2),
];
}
public function data(Theme $theme, array $data): array
{
return [
'heading' => $data['heading'] ?? null,
'text' => $data['text'] ?? null,
'owner' => config('fewo.owner'),
'address' => $theme->property()?->address,
];
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace App\Themes\Sections;
use App\Themes\Theme;
use Filament\Forms\Components\TextInput;
/**
* Key facts of the property (size, guests, highlights) – taken from the property and its equipment.
*/
class FactsSection extends Section
{
public static function key(): string
{
return 'facts';
}
public static function label(): string
{
return 'Eckdaten';
}
public static function icon(): string
{
return 'heroicon-o-squares-2x2';
}
public static function schema(): array
{
return [
TextInput::make('heading')->label('Überschrift (optional)')->maxLength(120),
];
}
public function data(Theme $theme, array $data): array
{
$property = $theme->property();
return [
'heading' => $data['heading'] ?? null,
'property' => $property,
'highlights' => $property?->amenities()->where('is_highlight', true)->limit(6)->pluck('name') ?? collect(),
'fromPrice' => $property?->seasons()->whereDate('ends_on', '>', today())->min('nightly_rate'),
];
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace App\Themes\Sections;
use App\Models\Faq;
use App\Themes\Theme;
use Filament\Forms\Components\TextInput;
/**
* Frequently asked questions (Admin › Webseite › Häufige Fragen), with FAQ structured data.
*/
class FaqSection extends Section
{
public static function key(): string
{
return 'faq';
}
public static function label(): string
{
return 'Häufige Fragen';
}
public static function icon(): string
{
return 'heroicon-o-question-mark-circle';
}
public static function schema(): array
{
return [
TextInput::make('heading')->label('Überschrift')->default('Häufige Fragen')->maxLength(120),
];
}
public function data(Theme $theme, array $data): array
{
$faqs = Faq::query()->published()->get();
return [
'heading' => $data['heading'] ?? null,
'faqs' => $faqs,
'answers' => $faqs->mapWithKeys(fn (Faq $faq): array => [$faq->id => $this->html($faq->answer)]),
];
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
namespace App\Themes\Sections;
use App\Enums\PhotoCategory;
use App\Models\Photo;
use App\Themes\Theme;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
/**
* Photo gallery of one category (or all), opened in a lightbox.
*/
class GallerySection extends Section
{
public static function key(): string
{
return 'gallery';
}
public static function label(): string
{
return 'Bildergalerie';
}
public static function icon(): string
{
return 'heroicon-o-rectangle-group';
}
public static function schema(): array
{
return [
TextInput::make('heading')->label('Überschrift')->maxLength(120),
Select::make('category')->label('Bilder')->options(['all' => 'Alle', ...collect(PhotoCategory::cases())->mapWithKeys(fn (PhotoCategory $category): array => [$category->value => $category->getLabel()])->all()])->default('all'),
TextInput::make('limit')->label('Anzahl (leer = alle)')->integer()->minValue(1),
];
}
public function data(Theme $theme, array $data): array
{
$category = PhotoCategory::tryFrom($data['category'] ?? '');
return [
'heading' => $data['heading'] ?? null,
'photos' => Photo::query()->published()->with('media')
->when($category, fn ($query) => $query->where('category', $category))
->when(filled($data['limit'] ?? null), fn ($query) => $query->limit((int) $data['limit']))
->get(),
];
}
}
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace App\Themes\Sections;
use App\Models\Photo;
use App\Themes\Theme;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
/**
* Large photo with headline and the availability search. Seasonal appearances replace photo and texts.
*/
class HeroSection extends Section
{
public static function key(): string
{
return 'hero';
}
public static function label(): string
{
return 'Titelbereich mit Suche';
}
public static function icon(): string
{
return 'heroicon-o-photo';
}
public static function schema(): array
{
return [
TextInput::make('eyebrow')->label('Kleine Überschrift')->maxLength(100),
TextInput::make('title')->label('Überschrift')->helperText('*Wort* wird hervorgehoben (kursiv).')->required()->maxLength(160),
Textarea::make('text')->label('Text')->rows(2)->maxLength(400),
static::photoSelect('photo_id', 'Foto (wenn das Erscheinungsbild keins vorgibt)'),
Toggle::make('show_search')->label('Verfügbarkeitssuche anzeigen')->default(true),
];
}
public function data(Theme $theme, array $data): array
{
$fallback = isset($data['photo_id']) ? Photo::find($data['photo_id']) : Photo::query()->published()->first();
return [
'eyebrow' => $theme->text('hero.eyebrow', $data['eyebrow'] ?? null),
'title' => $theme->text('hero.title', $data['title'] ?? $theme->site->name),
'text' => $theme->text('hero.text', $data['text'] ?? null),
'photo' => $theme->heroPhoto($fallback),
'showSearch' => (bool) ($data['show_search'] ?? true),
'property' => $theme->property(),
];
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace App\Themes\Sections;
use App\Support\Content;
use App\Themes\Theme;
use Filament\Forms\Components\TextInput;
/**
* The host: quote, text and photo from Admin › Texte › Gastgeber.
*/
class HostSection extends Section
{
public static function key(): string
{
return 'host';
}
public static function label(): string
{
return 'Gastgeber';
}
public static function icon(): string
{
return 'heroicon-o-user';
}
public static function schema(): array
{
return [
TextInput::make('heading')->label('Kleine Überschrift')->default('Ihre Gastgeberin')->maxLength(100),
];
}
public function data(Theme $theme, array $data): array
{
return [
'heading' => $data['heading'] ?? null,
'quote' => Content::get('host.quote'),
'text' => Content::html('host.text'),
'photo' => Content::photo('host.photo'),
'name' => config('fewo.owner.name'),
];
}
}
+57
View File
@@ -0,0 +1,57 @@
<?php
namespace App\Themes\Sections;
use App\Enums\PhotoCategory;
use App\Models\Photo;
use App\Themes\Theme;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
/**
* Location: text, photos of the area and a map link (no embedded third-party map, so no consent needed).
*/
class LocationSection extends Section
{
public static function key(): string
{
return 'location';
}
public static function label(): string
{
return 'Lage & Umgebung';
}
public static function icon(): string
{
return 'heroicon-o-map-pin';
}
public static function schema(): array
{
return [
TextInput::make('eyebrow')->label('Kleine Überschrift')->maxLength(100),
TextInput::make('heading')->label('Überschrift')->required()->maxLength(160),
RichEditor::make('text')->label('Text')->toolbarButtons([['bold', 'italic', 'link'], ['bulletList']]),
Toggle::make('show_photos')->label('Bilder der Umgebung zeigen')->default(true),
];
}
public function data(Theme $theme, array $data): array
{
$address = $theme->property()?->address;
return [
'eyebrow' => $data['eyebrow'] ?? null,
'heading' => $data['heading'] ?? '',
'text' => $this->html($data['text'] ?? null),
'address' => $address,
'mapUrl' => $address ? 'https://www.openstreetmap.org/search?query='.rawurlencode($address) : null,
'photos' => ($data['show_photos'] ?? true)
? Photo::query()->published()->with('media')->where('category', PhotoCategory::Area)->limit(6)->get()
: collect(),
];
}
}
+56
View File
@@ -0,0 +1,56 @@
<?php
namespace App\Themes\Sections;
use App\Models\SpecialOffer;
use App\Themes\Theme;
use Filament\Forms\Components\TextInput;
/**
* Public special offers (active, promoted, without code); the appearance's featured offer comes first.
*/
class OffersSection extends Section
{
public static function key(): string
{
return 'offers';
}
public static function label(): string
{
return 'Sonderangebote';
}
public static function icon(): string
{
return 'heroicon-o-sparkles';
}
public static function schema(): array
{
return [
TextInput::make('heading')->label('Überschrift')->default('Aktuelle Angebote')->maxLength(120),
];
}
public function data(Theme $theme, array $data): array
{
$offers = $theme->property()?->specialOffers()
->active()
->where('is_public', true)
->whereNull('code')
->where(fn ($query) => $query->whereNull('bookable_until')->orWhere('bookable_until', '>=', now()))
->get() ?? collect();
$featured = $theme->appearance?->featuredOffer;
if ($featured) {
$offers = $offers->reject(fn (SpecialOffer $offer): bool => $offer->is($featured))->prepend($featured);
}
return [
'heading' => $data['heading'] ?? null,
'offers' => $offers,
'featuredId' => $featured?->id,
];
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
namespace App\Themes\Sections;
use App\Themes\Theme;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
/**
* Season prices of the next twelve months, cleaning fee and extras – always the current price list.
*/
class PricesSection extends Section
{
public static function key(): string
{
return 'prices';
}
public static function label(): string
{
return 'Preise & Saisons';
}
public static function icon(): string
{
return 'heroicon-o-currency-euro';
}
public static function schema(): array
{
return [
TextInput::make('eyebrow')->label('Kleine Überschrift')->default('Preise')->maxLength(100),
TextInput::make('heading')->label('Überschrift')->default('Transparent, ohne Überraschungen.')->maxLength(160),
Textarea::make('text')->label('Text')->rows(2),
];
}
public function data(Theme $theme, array $data): array
{
$property = $theme->property();
return [
'eyebrow' => $data['eyebrow'] ?? null,
'heading' => $data['heading'] ?? '',
'text' => $data['text'] ?? null,
'property' => $property,
'seasons' => $property?->seasons()->whereDate('ends_on', '>', today())->whereDate('starts_on', '<', today()->addYear())->get() ?? collect(),
'extras' => $property?->extras()->active()->get() ?? collect(),
'featuredSeason' => $theme->appearance?->name,
];
}
}
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace App\Themes\Sections;
use App\Models\Review;
use App\Themes\Theme;
use Filament\Forms\Components\TextInput;
/**
* Approved guest reviews with average ratings and the legally required note on verification (§ 5b UWG).
*/
class ReviewsSection extends Section
{
public static function key(): string
{
return 'reviews';
}
public static function label(): string
{
return 'Gästebewertungen';
}
public static function icon(): string
{
return 'heroicon-o-star';
}
public static function schema(): array
{
return [
TextInput::make('heading')->label('Überschrift')->default('Das sagen unsere Gäste')->maxLength(120),
TextInput::make('limit')->label('Anzahl')->integer()->minValue(1)->default(6),
];
}
public function data(Theme $theme, array $data): array
{
$published = Review::query()->published()
->when($theme->property(), fn ($query, $property) => $query->whereBelongsTo($property));
return [
'heading' => $data['heading'] ?? null,
'reviews' => (clone $published)->limit((int) ($data['limit'] ?? 6))->get(),
'count' => (clone $published)->count(),
'average' => round((float) (clone $published)->avg('rating'), 1),
'categories' => collect(Review::CATEGORIES)
->map(fn (string $label, string $field): array => ['label' => $label, 'average' => round((float) (clone $published)->avg($field), 1)])
->filter(fn (array $category): bool => $category['average'] > 0)
->values(),
];
}
}
+64
View File
@@ -0,0 +1,64 @@
<?php
namespace App\Themes\Sections;
use App\Support\Content;
use App\Themes\Theme;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Utilities\Get;
/**
* Plain text page content – own text or one of the central texts (imprint, privacy policy, house rules …).
*/
class RichTextSection extends Section
{
/** Central texts that can be shown by reference, so they are maintained in one place. */
public const SOURCES = [
'own' => 'Eigener Text',
'legal.imprint' => 'Impressum (Texte › Rechtliches)',
'legal.privacy' => 'Datenschutzerklärung (Texte › Rechtliches)',
'stay.house_rules' => 'Hausregeln (Texte › Aufenthalt)',
'stay.cancellation' => 'Stornobedingungen (Texte › Aufenthalt)',
];
public static function key(): string
{
return 'rich_text';
}
public static function label(): string
{
return 'Fließtext';
}
public static function icon(): string
{
return 'heroicon-o-bars-3-bottom-left';
}
public static function schema(): array
{
return [
TextInput::make('heading')->label('Überschrift')->maxLength(160),
Select::make('source')->label('Inhalt')->options(self::SOURCES)->default('own')->live(),
RichEditor::make('text')
->label('Text')
->visible(fn (Get $get): bool => ($get('source') ?? 'own') === 'own')
->toolbarButtons([['bold', 'italic', 'link'], ['h2', 'h3'], ['bulletList', 'orderedList']]),
];
}
public function data(Theme $theme, array $data): array
{
$source = $data['source'] ?? 'own';
return [
'heading' => $data['heading'] ?? null,
'text' => $source === 'own' || ! array_key_exists($source, self::SOURCES)
? $this->html($data['text'] ?? null)
: (filled(Content::get($source)) ? Content::html($source) : null),
];
}
}
+109
View File
@@ -0,0 +1,109 @@
<?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();
}
}
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace App\Themes\Sections;
use App\Themes\Theme;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
/**
* Heading and text next to up to three photos, optionally with a link to another page.
*/
class TextImageSection extends Section
{
public static function key(): string
{
return 'text_image';
}
public static function label(): string
{
return 'Text mit Bildern';
}
public static function icon(): string
{
return 'heroicon-o-document-text';
}
public static function schema(): array
{
return [
TextInput::make('eyebrow')->label('Kleine Überschrift')->maxLength(100),
TextInput::make('heading')->label('Überschrift')->required()->maxLength(160),
RichEditor::make('text')->label('Text')->toolbarButtons([['bold', 'italic', 'link'], ['bulletList', 'orderedList']]),
static::photoSelect('photo_ids', 'Bilder (bis zu 3)', multiple: true)->maxItems(3),
Select::make('image_position')->label('Bilder')->options(['right' => 'rechts', 'left' => 'links'])->default('right'),
TextInput::make('link_label')->label('Link-Text')->maxLength(80),
static::pageSelect('link_page', 'Link zur Seite'),
];
}
public function data(Theme $theme, array $data): array
{
return [
'eyebrow' => $data['eyebrow'] ?? null,
'heading' => $data['heading'] ?? '',
'text' => $this->html($data['text'] ?? null),
'photos' => $this->photos($data['photo_ids'] ?? []),
'imagePosition' => $data['image_position'] ?? 'right',
'linkLabel' => $data['link_label'] ?? null,
'linkUrl' => $this->pageUrl($data['link_page'] ?? null),
];
}
}
+142
View File
@@ -0,0 +1,142 @@
<?php
namespace App\Themes;
use App\Models\Appearance;
use App\Models\Page;
use App\Models\Photo;
use App\Models\Property;
use App\Models\Site;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\View;
/**
* The theme context of the current request: site, theme chain and appearance. Activating it registers the
* view namespace "theme::" with the theme's own views first, then its parents, then the base theme.
*/
class Theme
{
private ?Property $property = null;
private bool $propertyResolved = false;
/** @var array<string, Collection<int, Page>> */
private array $menus = [];
public function __construct(
private ThemeRegistry $registry,
public readonly Site $site,
public readonly ?Appearance $appearance,
public readonly bool $isPreview = false,
) {}
public function activate(): self
{
$paths = array_map(fn (ThemeManifest $theme): string => $theme->viewsPath(), $this->chain());
View::replaceNamespace('theme', $paths);
return $this;
}
public function manifest(): ThemeManifest
{
return $this->registry->get($this->site->theme ?: config('themes.base'));
}
/**
* @return list<ThemeManifest>
*/
public function chain(): array
{
return $this->registry->chain($this->manifest()->key);
}
/**
* Colour tokens: theme defaults (base first, then children), site settings, appearance.
*
* @return array<string, string>
*/
public function tokens(): array
{
$tokens = [];
foreach (array_reverse($this->chain()) as $theme) {
foreach ($theme->tokens as $key => $token) {
$tokens[$key] = $token['default'];
}
}
$overrides = [...($this->site->theme_settings['tokens'] ?? []), ...($this->appearance?->tokens ?? [])];
foreach ($overrides as $key => $value) {
if (isset($tokens[$key]) && is_string($value) && preg_match('/^#[0-9a-fA-F]{3,8}$/', $value)) {
$tokens[$key] = $value;
}
}
return $tokens;
}
/**
* ":root{--ground:#F6F2EA;…}" for an inline <style> in the layout.
*/
public function cssVariables(): string
{
return ':root{'.collect($this->tokens())->map(fn (string $value, string $key): string => "--{$key}:{$value}")->implode(';').'}';
}
/**
* The appearance's replacement for a text, else $fallback.
*/
public function text(string $key, ?string $fallback = null): ?string
{
return $this->appearance?->override($key) ?? $fallback;
}
public function heroPhoto(?Photo $fallback = null): ?Photo
{
return $this->appearance?->heroPhoto ?? $fallback;
}
public function appearanceKey(): string
{
return $this->appearance ? str($this->appearance->name)->slug()->toString() : 'standard';
}
public function property(): ?Property
{
if (! $this->propertyResolved) {
$this->property = $this->site->exists ? $this->site->primaryProperty() : Property::query()->where('is_active', true)->first();
$this->propertyResolved = true;
}
return $this->property;
}
/**
* Published pages of a menu location ("main" or "footer").
*
* @return Collection<int, Page>
*/
public function menu(string $location): Collection
{
return $this->menus[$location] ??= $this->site->exists
? $this->site->pages()->where('is_published', true)->where('menu_location', $location)->get()
: collect();
}
/**
* Vite entry points of the active theme (a child theme without own assets uses its parent's).
*
* @return list<string>
*/
public function assets(): array
{
foreach ($this->chain() as $theme) {
$assets = array_values(array_filter([$theme->assets['css'] ?? null, $theme->assets['js'] ?? null]));
if ($assets !== []) {
return $assets;
}
}
return [];
}
}
+56
View File
@@ -0,0 +1,56 @@
<?php
namespace App\Themes;
use App\Models\Appearance;
use App\Models\Site;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Schema;
/**
* Builds the theme context: the site by host name (else the default site), the appearance in effect today –
* or the one named in a signed preview link (?vorschau=<id>).
*/
class ThemeFactory
{
public function __construct(private ThemeRegistry $registry) {}
public function forRequest(Request $request): Theme
{
$site = $this->site($request->getHost());
$preview = null;
if ($request->query('vorschau') && $request->hasValidSignature()) {
$preview = $site->appearances()->find($request->query('vorschau'));
}
return $this->forSite($site, $preview);
}
public function forSite(Site $site, ?Appearance $preview = null): Theme
{
return new Theme(
$this->registry,
$site,
$preview ?? ($site->exists ? $site->appearanceOn(today()) : null),
isPreview: $preview !== null,
);
}
public function site(?string $host = null): Site
{
if (! Schema::hasTable('sites')) {
return $this->fallbackSite();
}
return ($host ? Site::query()->where('domain', $host)->first() : null)
?? Site::query()->where('is_default', true)->first()
?? Site::query()->orderBy('id')->first()
?? $this->fallbackSite();
}
private function fallbackSite(): Site
{
return new Site(['name' => config('app.name'), 'theme' => config('themes.base')]);
}
}
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace App\Themes;
use InvalidArgumentException;
/**
* The contents of a theme's theme.json.
*/
final readonly class ThemeManifest
{
/**
* @param array<string, array{label: string, default: string}> $tokens colour tokens, exposed as CSS variables --<key>
* @param array{css?: string, js?: string} $assets Vite entry points relative to the project root
*/
public function __construct(
public string $key,
public string $name,
public string $version,
public ?string $parent,
public string $description,
public array $tokens,
public array $assets,
public string $path,
) {}
public static function fromFile(string $file): self
{
$data = json_decode((string) file_get_contents($file), true, flags: JSON_THROW_ON_ERROR);
if (! is_array($data) || blank($data['key'] ?? null) || blank($data['name'] ?? null)) {
throw new InvalidArgumentException("Invalid theme manifest [{$file}]: key and name are required.");
}
return new self(
key: $data['key'],
name: $data['name'],
version: $data['version'] ?? '0.0.0',
parent: $data['parent'] ?? null,
description: $data['description'] ?? '',
tokens: $data['tokens'] ?? [],
assets: $data['assets'] ?? [],
path: dirname($file),
);
}
public function viewsPath(): string
{
return $this->path.DIRECTORY_SEPARATOR.'views';
}
}
+67
View File
@@ -0,0 +1,67 @@
<?php
namespace App\Themes;
/**
* Discovers the themes below config('themes.paths').
*/
class ThemeRegistry
{
/** @var array<string, ThemeManifest>|null */
private ?array $themes = null;
/**
* @return array<string, ThemeManifest>
*/
public function all(): array
{
if ($this->themes === null) {
$this->themes = [];
foreach (config('themes.paths') as $path) {
foreach (glob(rtrim($path, '/\\').'/*/theme.json') ?: [] as $file) {
$manifest = ThemeManifest::fromFile($file);
$this->themes[$manifest->key] = $manifest;
}
}
}
return $this->themes;
}
public function get(string $key): ThemeManifest
{
return $this->all()[$key] ?? $this->all()[config('themes.base')];
}
/**
* The theme followed by its ancestors, ending with the base theme.
*
* @return list<ThemeManifest>
*/
public function chain(string $key): array
{
$chain = [];
$current = $this->get($key);
while (! isset($chain[$current->key])) {
$chain[$current->key] = $current;
if ($current->parent === null || ! isset($this->all()[$current->parent])) {
break;
}
$current = $this->all()[$current->parent];
}
$base = $this->get(config('themes.base'));
$chain[$base->key] ??= $base;
return array_values($chain);
}
/**
* @return array<string, string>
*/
public function options(): array
{
return array_map(fn (ThemeManifest $theme): string => "{$theme->name} ({$theme->version})", $this->all());
}
}