58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?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::forGalleries())->mapWithKeys(fn (PhotoCategory $category): array => [$category->value => $category->getLabel()])->all()])->default('all'),
|
|
TextInput::make('limit')->label('Anzahl (leer = alle)')->integer()->minValue(1),
|
|
];
|
|
}
|
|
|
|
public static function photoSlots(): array
|
|
{
|
|
return ['photo_ids' => ['label' => 'Galerie', 'type' => self::SLOT_COLLECTION]];
|
|
}
|
|
|
|
public function data(Theme $theme, array $data): array
|
|
{
|
|
$category = PhotoCategory::tryFrom($data['category'] ?? '');
|
|
|
|
return [
|
|
'heading' => $data['heading'] ?? null,
|
|
'photos' => $this->withSeasonalPhotos($theme, $data, 'photo_ids', Photo::query()->published()->forGalleries()->forProperty($theme->property())->with('media')
|
|
->when($category, fn ($query) => $query->where('category', $category))
|
|
->when(filled($data['limit'] ?? null), fn ($query) => $query->limit((int) $data['limit']))
|
|
->get()),
|
|
];
|
|
}
|
|
}
|