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:
1 parent
f2c48013ad
commit
66e82d61f5
119 files changed
+4066
-481
No files matched your search
@@ -39,7 +39,7 @@ class EditContent extends Page
|
||||
|
||||
protected static ?string $slug = 'texte';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
/** @var array<string, ?string> */
|
||||
public array $data = [];
|
||||
|
||||
@@ -27,7 +27,7 @@ class AmenityResource extends Resource
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Ausstattung';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
protected static ?int $navigationSort = 4;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Appearances;
|
||||
|
||||
use App\Filament\Resources\Appearances\Pages\CreateAppearance;
|
||||
use App\Filament\Resources\Appearances\Pages\EditAppearance;
|
||||
use App\Filament\Resources\Appearances\Pages\ListAppearances;
|
||||
use App\Filament\Resources\Appearances\Schemas\AppearanceForm;
|
||||
use App\Filament\Resources\Appearances\Tables\AppearancesTable;
|
||||
use App\Models\Appearance;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class AppearanceResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Appearance::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedSwatch;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Webseite';
|
||||
|
||||
protected static ?string $modelLabel = 'Erscheinungsbild';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Erscheinungsbilder';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return AppearanceForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return AppearancesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListAppearances::route('/'),
|
||||
'create' => CreateAppearance::route('/create'),
|
||||
'edit' => EditAppearance::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Appearances\Pages;
|
||||
|
||||
use App\Filament\Resources\Appearances\AppearanceResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateAppearance extends CreateRecord
|
||||
{
|
||||
protected static string $resource = AppearanceResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Appearances\Pages;
|
||||
|
||||
use App\Filament\Resources\Appearances\AppearanceResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditAppearance extends EditRecord
|
||||
{
|
||||
protected static string $resource = AppearanceResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Appearances\Pages;
|
||||
|
||||
use App\Filament\Resources\Appearances\AppearanceResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListAppearances extends ListRecords
|
||||
{
|
||||
protected static string $resource = AppearanceResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Appearances\Schemas;
|
||||
|
||||
use App\Models\Appearance;
|
||||
use App\Models\Photo;
|
||||
use App\Models\Site;
|
||||
use App\Models\SpecialOffer;
|
||||
use App\Themes\ThemeRegistry;
|
||||
use Closure;
|
||||
use Filament\Forms\Components\ColorPicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class AppearanceForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(2)
|
||||
->components([
|
||||
Section::make('Zeitraum')
|
||||
->description('Wiederholt sich jedes Jahr. Überschneiden sich Zeiträume, gilt die höhere Priorität (z. B. Silvester vor Winter). Ohne Zeitraum greift das Standard-Erscheinungsbild.')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('name')->label('Name')->placeholder('z. B. Weihnachten')->required()->maxLength(60),
|
||||
Select::make('site_id')
|
||||
->label('Website')
|
||||
->options(fn (): array => Site::query()->pluck('name', 'id')->all())
|
||||
->default(fn (): ?int => Site::query()->where('is_default', true)->value('id'))
|
||||
->required(),
|
||||
self::dayField('starts_md', 'Von (TT.MM.)'),
|
||||
self::dayField('ends_md', 'Bis einschließlich (TT.MM.)'),
|
||||
TextInput::make('priority')->label('Priorität')->integer()->minValue(0)->default(10),
|
||||
Toggle::make('is_default')->label('Standard (wenn kein Zeitraum passt)')->inline(false),
|
||||
Toggle::make('is_active')->label('Aktiv')->default(true)->inline(false),
|
||||
]),
|
||||
Section::make('Bild & Angebot')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Select::make('hero_photo_id')
|
||||
->label('Titelbild')
|
||||
->options(fn (): array => Photo::query()->orderBy('category')->orderBy('sort_order')->pluck('alt_text', 'id')->all())
|
||||
->searchable()
|
||||
->placeholder('Bild der Seite verwenden'),
|
||||
Select::make('featured_offer_id')
|
||||
->label('Hervorgehobenes Sonderangebot')
|
||||
->options(fn (): array => SpecialOffer::query()->where('is_active', true)->pluck('name', 'id')->all())
|
||||
->placeholder('keins'),
|
||||
]),
|
||||
Section::make('Texte')
|
||||
->description('Leer lassen = Text der Seite bzw. kein Banner.')
|
||||
->columns(2)
|
||||
->collapsible()
|
||||
->schema(collect(Appearance::OVERRIDABLE)
|
||||
->map(fn (string $label, string $key) => TextInput::make('overrides.'.$key)->label($label)->maxLength(255))
|
||||
->values()
|
||||
->all()),
|
||||
Section::make('Farben')
|
||||
->description('Nur ändern, was anders aussehen soll; leere Felder übernehmen die Farben des Themes.')
|
||||
->columns(3)
|
||||
->collapsible()
|
||||
->collapsed()
|
||||
->schema(fn (Get $get): array => self::tokenFields($get('site_id'))),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<ColorPicker>
|
||||
*/
|
||||
public static function tokenFields(int|string|null $siteId, string $statePath = 'tokens'): array
|
||||
{
|
||||
$theme = Site::find($siteId)?->theme ?? config('themes.base');
|
||||
|
||||
return collect(app(ThemeRegistry::class)->get($theme)->tokens)
|
||||
->map(fn (array $token, string $key): ColorPicker => ColorPicker::make("{$statePath}.{$key}")->label($token['label'])->placeholder($token['default']))
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Day of the year entered as "TT.MM." and stored as "MM-DD".
|
||||
*/
|
||||
private static function dayField(string $name, string $label): TextInput
|
||||
{
|
||||
return TextInput::make($name)
|
||||
->label($label)
|
||||
->placeholder('24.12.')
|
||||
->formatStateUsing(fn (?string $state): ?string => $state ? substr($state, 3, 2).'.'.substr($state, 0, 2).'.' : null)
|
||||
->dehydrateStateUsing(fn (?string $state): ?string => self::toMonthDay($state))
|
||||
->rule(fn (): Closure => function (string $attribute, mixed $value, Closure $fail): void {
|
||||
if (filled($value) && self::toMonthDay((string) $value) === null) {
|
||||
$fail('Bitte als TT.MM. eingeben, z. B. 24.12.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static function toMonthDay(?string $value): ?string
|
||||
{
|
||||
if (blank($value) || ! preg_match('/^\s*(\d{1,2})\.(\d{1,2})\.?\s*$/', $value, $match)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return checkdate((int) $match[2], (int) $match[1], 2024) ? sprintf('%02d-%02d', $match[2], $match[1]) : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Appearances\Tables;
|
||||
|
||||
use App\Models\Appearance;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
class AppearancesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('priority', 'desc')
|
||||
->description('Die Webseite wechselt automatisch nach Datum. Mit „Vorschau“ sehen Sie ein Erscheinungsbild schon vorher.')
|
||||
->columns([
|
||||
TextColumn::make('name')->label('Erscheinungsbild')->weight('medium'),
|
||||
TextColumn::make('period')
|
||||
->label('Zeitraum')
|
||||
->state(fn (Appearance $record): string => $record->is_default && ! $record->starts_md ? 'Standard' : self::day($record->starts_md).' – '.self::day($record->ends_md)),
|
||||
TextColumn::make('priority')->label('Priorität')->sortable(),
|
||||
IconColumn::make('current')
|
||||
->label('Jetzt aktiv')
|
||||
->boolean()
|
||||
->state(fn (Appearance $record): bool => $record->site?->appearanceOn(today())?->is($record) ?? false),
|
||||
ToggleColumn::make('is_active')->label('Aktiv'),
|
||||
])
|
||||
->recordActions([
|
||||
Action::make('preview')
|
||||
->label('Vorschau')
|
||||
->icon(Heroicon::OutlinedEye)
|
||||
->color('gray')
|
||||
->url(fn (Appearance $record): string => URL::temporarySignedRoute('home', now()->addDay(), ['vorschau' => $record->id]), shouldOpenInNewTab: true),
|
||||
EditAction::make(),
|
||||
DeleteAction::make()->visible(fn (Appearance $record): bool => ! $record->is_default),
|
||||
]);
|
||||
}
|
||||
|
||||
private static function day(?string $monthDay): string
|
||||
{
|
||||
return $monthDay ? substr($monthDay, 3, 2).'.'.substr($monthDay, 0, 2).'.' : '?';
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ class FaqResource extends Resource
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Häufige Fragen';
|
||||
|
||||
protected static ?int $navigationSort = 4;
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ class NoticeResource extends Resource
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Hinweis-Banner';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
protected static ?int $navigationSort = 6;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Pages;
|
||||
|
||||
use App\Filament\Resources\Pages\Pages\CreatePage;
|
||||
use App\Filament\Resources\Pages\Pages\EditPage;
|
||||
use App\Filament\Resources\Pages\Pages\ListPages;
|
||||
use App\Filament\Resources\Pages\Schemas\PageForm;
|
||||
use App\Filament\Resources\Pages\Tables\PagesTable;
|
||||
use App\Models\Page;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class PageResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Page::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedDocumentDuplicate;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Webseite';
|
||||
|
||||
protected static ?string $modelLabel = 'Seite';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Seiten';
|
||||
|
||||
protected static ?int $navigationSort = 0;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return PageForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return PagesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListPages::route('/'),
|
||||
'create' => CreatePage::route('/create'),
|
||||
'edit' => EditPage::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Pages\Pages;
|
||||
|
||||
use App\Filament\Resources\Pages\PageResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreatePage extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PageResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Pages\Pages;
|
||||
|
||||
use App\Filament\Resources\Pages\PageResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditPage extends EditRecord
|
||||
{
|
||||
protected static string $resource = PageResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Pages\Pages;
|
||||
|
||||
use App\Filament\Resources\Pages\PageResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListPages extends ListRecords
|
||||
{
|
||||
protected static string $resource = PageResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Pages\Schemas;
|
||||
|
||||
use App\Models\Page;
|
||||
use App\Models\Site;
|
||||
use App\Themes\SectionRegistry;
|
||||
use Filament\Forms\Components\Builder;
|
||||
use Filament\Forms\Components\Hidden;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Validation\Rules\Unique;
|
||||
|
||||
class PageForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(3)
|
||||
->components([
|
||||
Section::make('Bausteine')
|
||||
->description('Die Seite besteht aus Bausteinen. Reihenfolge per Ziehen, Inhalte je Baustein. Wie sie aussehen, bestimmt das Theme.')
|
||||
->columnSpan(2)
|
||||
->schema([
|
||||
Builder::make('sections')
|
||||
->hiddenLabel()
|
||||
->blocks(fn (): array => app(SectionRegistry::class)->blocks())
|
||||
->addActionLabel('Baustein hinzufügen')
|
||||
->collapsible()
|
||||
->collapsed()
|
||||
->cloneable()
|
||||
->blockNumbers(false)
|
||||
->blockPickerColumns(2),
|
||||
]),
|
||||
Section::make('Seite')
|
||||
->columnSpan(1)
|
||||
->schema([
|
||||
Hidden::make('site_id')->default(fn (): ?int => Site::query()->where('is_default', true)->value('id') ?? Site::query()->value('id')),
|
||||
TextInput::make('title')->label('Titel')->required()->maxLength(120),
|
||||
TextInput::make('slug')
|
||||
->label('Adresse')
|
||||
->prefix('/')
|
||||
->helperText('Die Startseite heißt „start“.')
|
||||
->required()
|
||||
->alphaDash()
|
||||
->maxLength(80)
|
||||
->disabled(fn (?Page $record): bool => $record?->isHome() ?? false)
|
||||
->dehydrated()
|
||||
->unique(ignoreRecord: true, modifyRuleUsing: fn (Unique $rule, callable $get) => $rule->where('site_id', $get('site_id'))),
|
||||
TextInput::make('menu_label')->label('Name im Menü (optional)')->maxLength(60),
|
||||
Select::make('menu_location')->label('Menü')->options(Page::MENU_LOCATIONS)->default('main')->required(),
|
||||
Toggle::make('is_published')->label('Veröffentlicht')->default(true),
|
||||
]),
|
||||
Section::make('Suchmaschinen')
|
||||
->columnSpan(1)
|
||||
->collapsed()
|
||||
->schema([
|
||||
TextInput::make('seo_title')->label('Seitentitel (Google)')->maxLength(70),
|
||||
Textarea::make('seo_description')->label('Beschreibung (Google)')->rows(3)->maxLength(170),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Pages\Tables;
|
||||
|
||||
use App\Models\Page;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class PagesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->reorderable('sort_order')
|
||||
->defaultSort('sort_order')
|
||||
->paginated(false)
|
||||
->description('Reihenfolge per Ziehen = Reihenfolge im Menü.')
|
||||
->columns([
|
||||
TextColumn::make('title')->label('Seite')->weight('medium')->description(fn (Page $record): string => $record->isHome() ? '/' : '/'.$record->slug),
|
||||
TextColumn::make('menu_location')->label('Menü')->formatStateUsing(fn (string $state): string => Page::MENU_LOCATIONS[$state] ?? $state)->badge(),
|
||||
TextColumn::make('sections')->label('Bausteine')->state(fn (Page $record): int => count($record->sections ?? [])),
|
||||
ToggleColumn::make('is_published')->label('Veröffentlicht'),
|
||||
])
|
||||
->recordActions([
|
||||
Action::make('open')
|
||||
->label('Ansehen')
|
||||
->icon(Heroicon::OutlinedArrowTopRightOnSquare)
|
||||
->color('gray')
|
||||
->url(fn (Page $record): string => $record->url(), shouldOpenInNewTab: true),
|
||||
EditAction::make(),
|
||||
DeleteAction::make()->visible(fn (Page $record): bool => ! $record->isHome()),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ class PhotoResource extends Resource
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Bilder';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Filament\Resources\Properties\Schemas;
|
||||
|
||||
use App\Filament\Forms\Components\EuroInput;
|
||||
use App\Models\Site;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\TimePicker;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
@@ -46,6 +48,10 @@ public static function configure(Schema $schema): Schema
|
||||
TimePicker::make('check_out_time')
|
||||
->label('Abreise bis')
|
||||
->seconds(false),
|
||||
Select::make('site_id')
|
||||
->label('Website')
|
||||
->options(fn (): array => Site::query()->pluck('name', 'id')->all())
|
||||
->placeholder('keine'),
|
||||
Toggle::make('is_active')
|
||||
->label('Aktiv (auf der Webseite buchbar)')
|
||||
->default(true),
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Sites\Pages;
|
||||
|
||||
use App\Filament\Resources\Sites\SiteResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateSite extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SiteResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Sites\Pages;
|
||||
|
||||
use App\Filament\Resources\Sites\SiteResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditSite extends EditRecord
|
||||
{
|
||||
protected static string $resource = SiteResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Sites\Pages;
|
||||
|
||||
use App\Filament\Resources\Sites\SiteResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListSites extends ListRecords
|
||||
{
|
||||
protected static string $resource = SiteResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Sites\Schemas;
|
||||
|
||||
use App\Filament\Resources\Appearances\Schemas\AppearanceForm;
|
||||
use App\Models\Site;
|
||||
use App\Themes\ThemeRegistry;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class SiteForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(2)
|
||||
->components([
|
||||
Section::make('Website')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('name')->label('Name')->required()->maxLength(120),
|
||||
TextInput::make('domain')
|
||||
->label('Domain')
|
||||
->placeholder('www.fewo-stommer.de')
|
||||
->helperText('Leer = Standard-Website für alle Adressen ohne eigene Zuordnung.')
|
||||
->unique(ignoreRecord: true)
|
||||
->maxLength(190),
|
||||
Select::make('theme')->label('Theme')->options(fn (): array => app(ThemeRegistry::class)->options())->default(config('themes.base'))->required()->live(),
|
||||
Toggle::make('is_default')->label('Standard-Website')->inline(false),
|
||||
]),
|
||||
Section::make('Farben des Themes')
|
||||
->description('Grundfarben dieser Website; saisonale Erscheinungsbilder können einzelne Farben zusätzlich ändern.')
|
||||
->columns(3)
|
||||
->collapsible()
|
||||
->schema(fn (Get $get, ?Site $record): array => AppearanceForm::tokenFields($record?->id, 'theme_settings.tokens')),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Sites;
|
||||
|
||||
use App\Filament\Resources\Sites\Pages\CreateSite;
|
||||
use App\Filament\Resources\Sites\Pages\EditSite;
|
||||
use App\Filament\Resources\Sites\Pages\ListSites;
|
||||
use App\Filament\Resources\Sites\Schemas\SiteForm;
|
||||
use App\Filament\Resources\Sites\Tables\SitesTable;
|
||||
use App\Models\Site;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class SiteResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Site::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedGlobeAlt;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'System';
|
||||
|
||||
protected static ?string $modelLabel = 'Website';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Websites';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return SiteForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return SitesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListSites::route('/'),
|
||||
'create' => CreateSite::route('/create'),
|
||||
'edit' => EditSite::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Sites\Tables;
|
||||
|
||||
use App\Themes\ThemeRegistry;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class SitesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')->label('Website')->weight('medium'),
|
||||
TextColumn::make('domain')->label('Domain')->placeholder('alle übrigen Adressen'),
|
||||
TextColumn::make('theme')->label('Theme')->formatStateUsing(fn (string $state): string => app(ThemeRegistry::class)->get($state)->name),
|
||||
TextColumn::make('properties_count')->label('Wohnungen')->counts('properties'),
|
||||
IconColumn::make('is_default')->label('Standard')->boolean(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Page;
|
||||
use App\Support\Content;
|
||||
use App\Themes\SectionRegistry;
|
||||
use App\Themes\Theme;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
/**
|
||||
* Renders the website pages of the current site with the active theme.
|
||||
*/
|
||||
class PageController extends Controller
|
||||
{
|
||||
public function __construct(private SectionRegistry $sections) {}
|
||||
|
||||
/**
|
||||
* Resolved per call: the controller is built before the middleware has determined site and appearance.
|
||||
*/
|
||||
private function theme(): Theme
|
||||
{
|
||||
return app(Theme::class);
|
||||
}
|
||||
|
||||
public function home(): View
|
||||
{
|
||||
return $this->show(Page::HOME);
|
||||
}
|
||||
|
||||
public function show(string $slug): View
|
||||
{
|
||||
abort_unless($this->theme()->site->exists, 404);
|
||||
|
||||
$page = $this->theme()->site->pages()
|
||||
->where('slug', $slug)
|
||||
->where('is_published', true)
|
||||
->firstOrFail();
|
||||
|
||||
return view('theme::page', [
|
||||
'page' => $page,
|
||||
'sections' => $this->sections->render($this->theme(), $page->sections),
|
||||
'title' => $page->isHome() ? null : ($page->seo_title ?: $page->title),
|
||||
'description' => $page->seo_description ?: ($page->isHome() ? Content::get('seo.home.description') : null),
|
||||
'ogImage' => $this->theme()->heroPhoto()?->url('lg') ?: null,
|
||||
'structuredData' => $page->isHome() ? $this->structuredData() : null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function sitemap(): Response
|
||||
{
|
||||
$pages = $this->theme()->site->exists
|
||||
? $this->theme()->site->pages()->where('is_published', true)->get()
|
||||
: collect();
|
||||
|
||||
return response()->view('sitemap', ['pages' => $pages], 200, ['Content-Type' => 'application/xml']);
|
||||
}
|
||||
|
||||
public function robots(): Response
|
||||
{
|
||||
return response(implode("\n", [
|
||||
'User-agent: *',
|
||||
'Disallow: /admin',
|
||||
'Disallow: /livewire',
|
||||
'Disallow: /automation',
|
||||
'Disallow: /bewertung',
|
||||
'Disallow: /angebote',
|
||||
'Sitemap: '.route('sitemap'),
|
||||
'',
|
||||
]), 200, ['Content-Type' => 'text/plain; charset=UTF-8']);
|
||||
}
|
||||
|
||||
/**
|
||||
* schema.org data of the property for search engines.
|
||||
*
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
private function structuredData(): ?array
|
||||
{
|
||||
$property = $this->theme()->property();
|
||||
if ($property === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return array_filter([
|
||||
'@context' => 'https://schema.org',
|
||||
'@type' => 'VacationRental',
|
||||
'name' => $property->name,
|
||||
'url' => route('home'),
|
||||
'image' => $this->theme()->heroPhoto()?->url('lg') ?: null,
|
||||
'address' => ['@type' => 'PostalAddress', 'streetAddress' => str($property->address)->before(',')->trim()->toString(), 'addressLocality' => 'Kühlungsborn', 'postalCode' => '18225', 'addressCountry' => 'DE'],
|
||||
'containsPlace' => ['@type' => 'Accommodation', 'floorSize' => ['@type' => 'QuantitativeValue', 'value' => $property->size_sqm, 'unitCode' => 'MTK'], 'occupancy' => ['@type' => 'QuantitativeValue', 'maxValue' => $property->max_guests]],
|
||||
'telephone' => config('fewo.owner.phone'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Themes\Theme;
|
||||
use App\Themes\ThemeFactory;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Determines site, theme and appearance for the website and activates the "theme::" views.
|
||||
*/
|
||||
class ResolveTheme
|
||||
{
|
||||
public function __construct(private ThemeFactory $factory) {}
|
||||
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
app()->instance(Theme::class, $this->factory->forRequest($request)->activate());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,7 @@ public function mount(?Property $property = null): void
|
||||
{
|
||||
$this->propertyId = ($property ?? Property::query()->where('is_active', true)->firstOrFail())->id;
|
||||
$this->month = CarbonImmutable::today()->format('Y-m');
|
||||
$this->prefillFromSearch();
|
||||
$this->utm = collect(request()->only(['utm_source', 'utm_medium', 'utm_campaign']))
|
||||
->filter(fn ($value): bool => is_string($value) && $value !== '')
|
||||
->map(fn (string $value): string => mb_substr($value, 0, 100))
|
||||
@@ -314,6 +315,26 @@ private function stayRequest(): StayRequest
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dates and guests from the availability search of the hero section (?anreise=…&abreise=…&personen=…).
|
||||
*/
|
||||
private function prefillFromSearch(): void
|
||||
{
|
||||
$arrival = rescue(fn () => CarbonImmutable::createFromFormat('!Y-m-d', (string) request()->query('anreise')) ?: null, null, false);
|
||||
$departure = rescue(fn () => CarbonImmutable::createFromFormat('!Y-m-d', (string) request()->query('abreise')) ?: null, null, false);
|
||||
|
||||
if ($arrival && $departure && $departure->greaterThan($arrival) && $arrival->greaterThanOrEqualTo(CarbonImmutable::today())) {
|
||||
$this->arrival = $arrival->toDateString();
|
||||
$this->departure = $departure->toDateString();
|
||||
$this->month = $arrival->format('Y-m');
|
||||
}
|
||||
|
||||
$guests = (int) request()->query('personen');
|
||||
if ($guests >= 1 && $guests <= $this->property->max_guests) {
|
||||
$this->guests = $guests;
|
||||
}
|
||||
}
|
||||
|
||||
private function firstMonth(): CarbonImmutable
|
||||
{
|
||||
return CarbonImmutable::createFromFormat('!Y-m', $this->month);
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\CarbonInterface;
|
||||
use Database\Factories\AppearanceFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* A seasonal look of a site (e.g. summer, winter, Christmas, New Year's Eve): colour tokens, hero photo,
|
||||
* texts and banner change – the page structure does not. The period recurs every year ("MM-DD" to "MM-DD",
|
||||
* inclusive; a period may run over the turn of the year). The default appearance applies when none matches.
|
||||
*/
|
||||
#[Fillable(['site_id', 'name', 'starts_md', 'ends_md', 'priority', 'is_default', 'is_active', 'tokens', 'overrides', 'hero_photo_id', 'featured_offer_id'])]
|
||||
class Appearance extends Model
|
||||
{
|
||||
/** @use HasFactory<AppearanceFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Texts an appearance can replace, with their admin labels. Sections read them through Theme::text().
|
||||
*/
|
||||
public const OVERRIDABLE = [
|
||||
'banner.text' => 'Banner: Text',
|
||||
'banner.link_label' => 'Banner: Link-Text',
|
||||
'banner.link_url' => 'Banner: Link-Ziel',
|
||||
'hero.eyebrow' => 'Titelbereich: kleine Überschrift',
|
||||
'hero.title' => 'Titelbereich: Überschrift',
|
||||
'hero.text' => 'Titelbereich: Text',
|
||||
'cta.title' => 'Abschluss: Überschrift',
|
||||
'cta.text' => 'Abschluss: Text',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_default' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
'tokens' => 'array',
|
||||
'overrides' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Site, $this>
|
||||
*/
|
||||
public function site(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Site::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Photo, $this>
|
||||
*/
|
||||
public function heroPhoto(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Photo::class, 'hero_photo_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<SpecialOffer, $this>
|
||||
*/
|
||||
public function featuredOffer(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(SpecialOffer::class, 'featured_offer_id');
|
||||
}
|
||||
|
||||
public function covers(CarbonInterface $date): bool
|
||||
{
|
||||
if ($this->starts_md === null || $this->ends_md === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$day = $date->format('m-d');
|
||||
|
||||
return $this->starts_md <= $this->ends_md
|
||||
? $day >= $this->starts_md && $day <= $this->ends_md
|
||||
: $day >= $this->starts_md || $day <= $this->ends_md;
|
||||
}
|
||||
|
||||
public function override(string $key): ?string
|
||||
{
|
||||
$value = data_get($this->overrides, $key);
|
||||
|
||||
return filled($value) ? (string) $value : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\PageFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* A page of a site, composed of sections from the catalogue (App\Themes\Sections).
|
||||
* sections = list of {type: string, data: array} as stored by the Filament builder.
|
||||
* The home page has the slug "start" and is served at "/".
|
||||
*/
|
||||
#[Fillable(['site_id', 'slug', 'title', 'menu_label', 'menu_location', 'sort_order', 'is_published', 'sections', 'seo_title', 'seo_description'])]
|
||||
class Page extends Model
|
||||
{
|
||||
/** @use HasFactory<PageFactory> */
|
||||
use HasFactory;
|
||||
|
||||
public const HOME = 'start';
|
||||
|
||||
/** Menu locations a page can appear in. */
|
||||
public const MENU_LOCATIONS = ['main' => 'Hauptmenü', 'footer' => 'Fußzeile', 'none' => 'Nicht im Menü'];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_published' => 'boolean',
|
||||
'sections' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Site, $this>
|
||||
*/
|
||||
public function site(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Site::class);
|
||||
}
|
||||
|
||||
public function isHome(): bool
|
||||
{
|
||||
return $this->slug === self::HOME;
|
||||
}
|
||||
|
||||
public function url(): string
|
||||
{
|
||||
return $this->isHome() ? route('home') : route('page', ['slug' => $this->slug]);
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return $this->menu_label ?: $this->title;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
* A rentable holiday apartment. All money amounts are stored in euro cents.
|
||||
*/
|
||||
#[Fillable([
|
||||
'site_id',
|
||||
'name',
|
||||
'slug',
|
||||
'address',
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\CarbonInterface;
|
||||
use Database\Factories\SiteFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* A website: domain, theme with its settings, pages and appearances, and the properties it shows.
|
||||
* Today there is one site; more sites allow other landlords to use the system under their own domain.
|
||||
*/
|
||||
#[Fillable(['name', 'domain', 'is_default', 'theme', 'theme_settings', 'locale'])]
|
||||
class Site extends Model
|
||||
{
|
||||
/** @use HasFactory<SiteFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_default' => 'boolean',
|
||||
'theme_settings' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<Page, $this>
|
||||
*/
|
||||
public function pages(): HasMany
|
||||
{
|
||||
return $this->hasMany(Page::class)->orderBy('sort_order');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<Appearance, $this>
|
||||
*/
|
||||
public function appearances(): HasMany
|
||||
{
|
||||
return $this->hasMany(Appearance::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<Property, $this>
|
||||
*/
|
||||
public function properties(): HasMany
|
||||
{
|
||||
return $this->hasMany(Property::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The property sections show when they do not name one (the first active property).
|
||||
*/
|
||||
public function primaryProperty(): ?Property
|
||||
{
|
||||
return $this->properties()->where('is_active', true)->orderBy('id')->first()
|
||||
?? Property::query()->where('is_active', true)->whereNull('site_id')->orderBy('id')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* The appearance in effect on $date: the active seasonal one with the highest priority, else the default.
|
||||
*/
|
||||
public function appearanceOn(CarbonInterface $date): ?Appearance
|
||||
{
|
||||
$appearances = $this->appearances()->where('is_active', true)->get();
|
||||
|
||||
return $appearances
|
||||
->filter(fn (Appearance $appearance): bool => $appearance->covers($date))
|
||||
->sortByDesc('priority')
|
||||
->first()
|
||||
?? $appearances->firstWhere('is_default', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
|
||||
class AppearancePolicy extends RolePolicy
|
||||
{
|
||||
protected function roles(): array
|
||||
{
|
||||
return [UserRole::Content];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
|
||||
class PagePolicy extends RolePolicy
|
||||
{
|
||||
protected function roles(): array
|
||||
{
|
||||
return [UserRole::Content];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
class SitePolicy extends RolePolicy
|
||||
{
|
||||
protected function roles(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Themes\SectionRegistry;
|
||||
use App\Themes\Theme;
|
||||
use App\Themes\ThemeFactory;
|
||||
use App\Themes\ThemeRegistry;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class ThemeServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->singleton(ThemeRegistry::class);
|
||||
$this->app->singleton(SectionRegistry::class);
|
||||
|
||||
// Outside web requests (console, tests, mails) the default site's theme is used.
|
||||
$this->app->singleton(Theme::class, fn ($app): Theme => $app->make(ThemeFactory::class)
|
||||
->forSite($app->make(ThemeFactory::class)->site())
|
||||
->activate());
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,9 @@ public static function get(string $key): ?string
|
||||
*/
|
||||
public static function html(string $key): HtmlString
|
||||
{
|
||||
return new HtmlString(RichContentRenderer::make(self::get($key) ?? '')->toHtml());
|
||||
$value = self::get($key);
|
||||
|
||||
return new HtmlString(filled($value) ? RichContentRenderer::make($value)->toHtml() : '');
|
||||
}
|
||||
|
||||
public static function photo(string $key): ?Photo
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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()),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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)]),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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 [];
|
||||
}
|
||||
}
|
||||
@@ -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')]);
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user