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[
][]. * * @return list */ 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 */ 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; } }