Files
fewo-stommer/app/Filament/Resources/Photos/Schemas/PhotoForm.php
T
LarsandClaude Opus 5.5 791786ed3e Saisonfotos am Foto statt am Erscheinungsbild
Ein Foto gehoert zu keinem (ganzjaehrig) oder mehreren Erscheinungsbildern und
erscheint nur dort, vor den ganzjaehrigen Fotos. Bausteine waehlen "automatisch"
oder eine eigene Auswahl; Titelbereich und Abschluss zeigen das erste passende
Foto ihrer Liste. Titelbild und "Bilder je Baustein" des Erscheinungsbilds werden
in die Bausteine uebernommen und entfallen dort.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 18:53:56 +01:00

77 lines
3.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Filament\Resources\Photos\Schemas;
use App\Enums\PhotoCategory;
use App\Models\Appearance;
use App\Models\Photo;
use App\Models\Property;
use App\Support\CurrentProperty;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Schema;
class PhotoForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->columns(2)
->components([
SpatieMediaLibraryFileUpload::make('image')
->label('Bild')
->collection(Photo::COLLECTION)
->disk('public')
->image()
->imageEditor()
->maxSize(25 * 1024)
->helperText('JPG, PNG oder WebP bis 25 MB. Große Originale sind willkommen – Web-Größen werden automatisch erzeugt.')
->required()
->columnSpanFull(),
TextInput::make('alt_text')
->label('Bildbeschreibung')
->helperText('Kurz beschreiben, was zu sehen ist – wichtig für Google und für blinde Besucher.')
->required()
->maxLength(255),
TextInput::make('caption')
->label('Bildunterschrift (optional)')
->maxLength(255),
Select::make('category')
->label('Kategorie')
->options(PhotoCategory::class)
->default(PhotoCategory::Apartment)
->required(),
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) –'),
Select::make('appearance_ids')
->label('Zeigen in')
->multiple()
->options(fn (): array => Appearance::photoOptions())
->placeholder('ganzjährig')
->helperText('Leer = ganzjährig. Mit Auswahl erscheint das Foto nur in diesen Erscheinungsbildern – dann vor den ganzjährigen Fotos.')
->dehydrateStateUsing(fn (?array $state): ?array => self::appearanceIds($state)),
Toggle::make('is_published')
->label('Auf der Webseite zeigen')
->default(true),
]);
}
/**
* Selected appearances as integers, null for "all year".
*
* @param array<int|string>|null $state
* @return list<int>|null
*/
public static function appearanceIds(?array $state): ?array
{
$ids = array_values(array_unique(array_map('intval', array_filter((array) $state))));
return $ids === [] ? null : $ids;
}
}