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
@@ -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),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user