Files
fewo-stommer/app/Support/Content.php
T
Lars StommerandClaude Opus 5.5 66e82d61f5 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>
2026-10-22 15:04:21 +02:00

90 lines
2.3 KiB
PHP

<?php
namespace App\Support;
use App\Models\ContentBlock;
use App\Models\Photo;
use Filament\Forms\Components\RichEditor\RichContentRenderer;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\HtmlString;
use InvalidArgumentException;
/**
* Read access to the editable website texts defined in config/content.php.
*/
class Content
{
private const CACHE_KEY = 'content-blocks';
/**
* The stored value, or the configured default when nothing was saved.
*/
public static function get(string $key): ?string
{
$definition = self::definition($key);
$stored = self::stored()[$key] ?? null;
return filled($stored) ? $stored : ($definition['default'] ?? null);
}
/**
* Rich text as sanitised HTML, ready for {{ }} output in Blade.
*/
public static function html(string $key): HtmlString
{
$value = self::get($key);
return new HtmlString(filled($value) ? RichContentRenderer::make($value)->toHtml() : '');
}
public static function photo(string $key): ?Photo
{
$id = self::get($key);
return $id ? Photo::find((int) $id) : null;
}
/**
* @param array<string, ?string> $values
*/
public static function save(array $values): void
{
foreach ($values as $key => $value) {
self::definition($key);
ContentBlock::updateOrCreate(['key' => $key], ['value' => $value]);
}
Cache::forget(self::CACHE_KEY);
}
/**
* @return array<string, array{label: string, fields: array<string, array{label: string, type: string, default?: ?string}>}>
*/
public static function sections(): array
{
return config('content');
}
/**
* @return array{label: string, type: string, default?: ?string}
*/
private static function definition(string $key): array
{
foreach (self::sections() as $section) {
if (isset($section['fields'][$key])) {
return $section['fields'][$key];
}
}
throw new InvalidArgumentException("Unknown content key [{$key}].");
}
/**
* @return array<string, ?string>
*/
private static function stored(): array
{
return Cache::rememberForever(self::CACHE_KEY, fn (): array => ContentBlock::pluck('value', 'key')->all());
}
}