- Special offers: kinds (rule, fixed dates, gap filler), package price, priority, highlight;
GapFinder detects calendar gaps (optionally waiving the minimum stay); OfferShowcase decides
what the website advertises and prices fixed dates/gaps with PriceCalculator; offers section
shows them side by side, as a list or rotating; hero can show the top offer. Appearances no
longer carry a featured offer.
- Sections get stable ids; appearances set photos per section ("Bilder je Baustein") and
sections can be limited to appearances. Photo pickers show thumbnails everywhere.
- Themes: themes:make (scaffold, never overwrites), themes:check (contract, build, markup,
colours, external resources, WCAG contrast), themes:preview (signed links per page and
appearance), signed ?theme= preview and preview action in the site form, inherited colour
tokens in the admin. Base CSS split into theme.css + reusable theme-base.css.
- docs/THEME-ERSTELLUNG.md: binding guide for building additional themes elsewhere.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
170 lines
7.9 KiB
PHP
170 lines
7.9 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Resources\Appearances\Schemas;
|
||
|
||
use App\Filament\Forms\Components\PhotoSelect;
|
||
use App\Models\Appearance;
|
||
use App\Models\Page;
|
||
use App\Models\Site;
|
||
use App\Themes\SectionRegistry;
|
||
use App\Themes\Sections\Section as SectionBlock;
|
||
use App\Themes\ThemeRegistry;
|
||
use Closure;
|
||
use Filament\Forms\Components\ColorPicker;
|
||
use Filament\Forms\Components\Radio;
|
||
use Filament\Forms\Components\Select;
|
||
use Filament\Forms\Components\TextInput;
|
||
use Filament\Forms\Components\Toggle;
|
||
use Filament\Schemas\Components\Component;
|
||
use Filament\Schemas\Components\Fieldset;
|
||
use Filament\Schemas\Components\Section;
|
||
use Filament\Schemas\Components\Text;
|
||
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('Titelbild')
|
||
->description('Gilt für alle Titelbereiche und als Vorschaubild beim Teilen in sozialen Medien – einzelne Bausteine können unten ein eigenes Bild bekommen. Sonderangebote werden unabhängig vom Erscheinungsbild beworben (Wohnung › Sonderangebote).')
|
||
->schema([
|
||
PhotoSelect::make('hero_photo_id')
|
||
->label('Titelbild')
|
||
->placeholder('Bild der Seite verwenden'),
|
||
]),
|
||
Section::make('Bilder je Baustein')
|
||
->description('Für jeden Baustein mit Bildern ein eigenes Saisonbild wählen. Leer = Bild aus der Seite. Neue Bilder laden Sie unter Webseite › Fotos hoch.')
|
||
->collapsible()
|
||
->columnSpanFull()
|
||
->schema(fn (Get $get): array => self::sectionPhotoFields($get('site_id'))),
|
||
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'))),
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* One group per page and one field set per placed section that has photo slots
|
||
* (see Section::photoSlots); stored in section_photos[<section id>][<slot>].
|
||
*
|
||
* @return list<Component>
|
||
*/
|
||
public static function sectionPhotoFields(int|string|null $siteId): array
|
||
{
|
||
$registry = app(SectionRegistry::class);
|
||
$pages = Page::query()->where('site_id', $siteId)->orderBy('sort_order')->get();
|
||
|
||
$groups = [];
|
||
foreach ($pages as $page) {
|
||
$fieldsets = [];
|
||
foreach ($page->sections ?? [] as $stored) {
|
||
$class = $registry->all()[$stored['type'] ?? ''] ?? null;
|
||
$sectionId = $stored['data']['id'] ?? null;
|
||
if ($class === null || blank($sectionId) || $class::photoSlots() === []) {
|
||
continue;
|
||
}
|
||
|
||
$fields = [];
|
||
foreach ($class::photoSlots() as $slot => $definition) {
|
||
$field = PhotoSelect::make("section_photos.{$sectionId}.{$slot}")
|
||
->label($definition['label'])
|
||
->placeholder('Standard (Bild aus der Seite)')
|
||
->multiple($definition['type'] !== SectionBlock::SLOT_SINGLE);
|
||
if (isset($definition['max'])) {
|
||
$field->maxItems($definition['max']);
|
||
}
|
||
$fields[] = $field;
|
||
|
||
if ($definition['type'] === SectionBlock::SLOT_COLLECTION) {
|
||
$fields[] = Radio::make("section_photos.{$sectionId}.mode")
|
||
->label('Saisonbilder')
|
||
->options(['replace' => 'ersetzen die Bilder des Bausteins', 'prepend' => 'kommen zuerst, danach die übrigen'])
|
||
->default('replace')
|
||
->inline();
|
||
}
|
||
}
|
||
|
||
$fieldsets[] = Fieldset::make(collect([$class::label(), $class::summary($stored['data'] ?? [])])->filter()->implode(' · '))
|
||
->columns(1)
|
||
->schema($fields);
|
||
}
|
||
|
||
if ($fieldsets !== []) {
|
||
$groups[] = Section::make($page->title)->compact()->collapsible()->schema($fieldsets);
|
||
}
|
||
}
|
||
|
||
return $groups ?: [Text::make('Auf den Seiten gibt es noch keine Bausteine mit Bildern.')];
|
||
}
|
||
|
||
/**
|
||
* @return list<ColorPicker>
|
||
*/
|
||
public static function tokenFields(int|string|null $siteId, string $statePath = 'tokens', ?string $themeKey = null): array
|
||
{
|
||
$theme = $themeKey ?: (Site::find($siteId)?->theme ?? config('themes.base'));
|
||
|
||
return collect(app(ThemeRegistry::class)->tokens($theme))
|
||
->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;
|
||
}
|
||
}
|