- Weitere Adressen einer Website (z. B. www.stommer.info) leiten per 301 auf die Hauptadresse um; vorher blockierte der Browser Skripte, Schriften und Videos, die von der Hauptadresse kamen (kein Titelvideo, Ersatzschrift) - Site::origin() nimmt verbindlich das Feld domain - Videos: Abspielgeschwindigkeit 0,5x bis 1x, gilt im Titelbereich und Rundgang Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
121 lines
5.8 KiB
PHP
121 lines
5.8 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Resources\Videos\Schemas;
|
||
|
||
use App\Models\FloorPlan;
|
||
use App\Models\Property;
|
||
use App\Models\Video;
|
||
use App\Support\CurrentProperty;
|
||
use Closure;
|
||
use Filament\Forms\Components\Repeater;
|
||
use Filament\Forms\Components\Select;
|
||
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
|
||
use Filament\Forms\Components\TextInput;
|
||
use Filament\Schemas\Components\Section;
|
||
use Filament\Schemas\Components\Utilities\Get;
|
||
use Filament\Schemas\Schema;
|
||
|
||
class VideoForm
|
||
{
|
||
public static function configure(Schema $schema): Schema
|
||
{
|
||
return $schema
|
||
->columns(2)
|
||
->components([
|
||
SpatieMediaLibraryFileUpload::make('file')
|
||
->label('Videodatei')
|
||
->collection(Video::COLLECTION)
|
||
->disk('public')
|
||
->acceptedFileTypes(['video/mp4', 'application/mp4', 'video/webm'])
|
||
->maxSize(Video::MAX_KB)
|
||
->helperText('MP4 (H.264) oder WebM bis 100 MB. Für den Titelbereich reicht eine kurze stumme Schleife von 6–10 Sekunden und 2–4 MB – sie lädt auf jedem Handy mit.')
|
||
->required()
|
||
->columnSpanFull(),
|
||
SpatieMediaLibraryFileUpload::make('poster')
|
||
->label('Standbild')
|
||
->collection(Video::POSTER)
|
||
->disk('public')
|
||
->image()
|
||
->maxSize(25 * 1024)
|
||
->helperText('Wird gezeigt, bis das Video läuft, und statt des Videos, wenn Besucher „Bewegung reduzieren“ eingestellt haben. Am besten ein Bild aus dem Video.')
|
||
->required()
|
||
->columnSpanFull(),
|
||
TextInput::make('title')
|
||
->label('Titel')
|
||
->helperText('Für Sie zur Auswahl in den Bausteinen und für Screenreader („Video: …“).')
|
||
->required()
|
||
->maxLength(160),
|
||
Select::make('property_id')
|
||
->label('Wohnung')
|
||
->options(fn (): array => Property::query()->pluck('name', 'id')->all())
|
||
->default(fn (): ?int => app(CurrentProperty::class)->id())
|
||
->placeholder('– keine (z. B. Umgebung) –')
|
||
->live(),
|
||
Select::make('playback_rate')
|
||
->label('Abspielgeschwindigkeit')
|
||
->helperText('Gilt überall, wo das Video gezeigt wird – im Titelbereich und im Rundgang. Drohnenflüge wirken mit 0,75× ruhiger; unter 0,6× kann die Bewegung ruckeln. Kapitelzeiten bleiben gleich.')
|
||
->options(Video::PLAYBACK_RATES)
|
||
->formatStateUsing(fn (mixed $state): string => self::rateKey($state))
|
||
->dehydrateStateUsing(fn (mixed $state): float => (float) $state)
|
||
->default('1')
|
||
->selectablePlaceholder(false)
|
||
->required(),
|
||
Section::make('Kapitel')
|
||
->description('Für den Rundgang: Besucher springen per Knopf zu einem Raum. Ist ein Raum aus dem Grundriss gewählt, bietet der Grundriss bei diesem Raum „Im Video ansehen“ an.')
|
||
->collapsible()
|
||
->columnSpanFull()
|
||
->schema([
|
||
Repeater::make('chapters')
|
||
->hiddenLabel()
|
||
->addActionLabel('Kapitel hinzufügen')
|
||
->columns(3)
|
||
->defaultItems(0)
|
||
->reorderable(false)
|
||
->itemLabel(fn (array $state): ?string => trim(($state['at'] ?? '').' '.($state['label'] ?? '')) ?: null)
|
||
->schema([
|
||
TextInput::make('at')
|
||
->label('Ab (Min:Sek)')
|
||
->placeholder('0:16')
|
||
->required()
|
||
->rules([fn (): Closure => function (string $attribute, mixed $value, Closure $fail): void {
|
||
if (Video::seconds($value) === null) {
|
||
$fail('Bitte als Minuten:Sekunden angeben, z. B. 0:16 oder 1:05.');
|
||
}
|
||
}]),
|
||
TextInput::make('label')
|
||
->label('Bezeichnung')
|
||
->placeholder('Wohnzimmer')
|
||
->required()
|
||
->maxLength(60),
|
||
Select::make('room')
|
||
->label('Raum im Grundriss')
|
||
->options(fn (Get $get): array => self::roomOptions($get('../../property_id')))
|
||
->placeholder('– keiner –'),
|
||
]),
|
||
]),
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* Option key for a stored rate (0.75 → "0.75", 1.0 → "1"); unknown values fall back to the original speed.
|
||
*/
|
||
public static function rateKey(mixed $rate): string
|
||
{
|
||
$key = rtrim(rtrim(number_format((float) ($rate ?: 1), 2, '.', ''), '0'), '.');
|
||
|
||
return array_key_exists($key, Video::PLAYBACK_RATES) ? $key : '1';
|
||
}
|
||
|
||
/**
|
||
* Names of the visible floor plan rooms of the apartment (name => name).
|
||
*
|
||
* @return array<string, string>
|
||
*/
|
||
public static function roomOptions(mixed $propertyId): array
|
||
{
|
||
$plan = filled($propertyId) ? FloorPlan::query()->where('property_id', $propertyId)->first() : null;
|
||
|
||
return $plan?->visibleRooms()->pluck('name', 'name')->all() ?? [];
|
||
}
|
||
}
|