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>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-10-29 18:53:56 +01:00
1 parent d02f3e05c7
commit 791786ed3e
21 files changed
+449 -235

No files matched your search

+55 -57
View File
@@ -2,13 +2,16 @@
namespace App\Themes\Sections;
use App\Enums\PhotoCategory;
use App\Filament\Forms\Components\PhotoSelect;
use App\Models\Page;
use App\Models\Photo;
use App\Themes\Theme;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\RichEditor\RichContentRenderer;
use Filament\Forms\Components\Select;
use Filament\Schemas\Components\Component;
use Filament\Schemas\Components\Utilities\Get;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\HtmlString;
@@ -18,14 +21,8 @@
*/
abstract class Section
{
/** One photo (field holds a photo id). */
public const SLOT_SINGLE = 'single';
/** Several chosen photos (field holds a list of ids). */
public const SLOT_MULTIPLE = 'multiple';
/** Photos picked automatically (e.g. by category); an appearance may replace or precede them. */
public const SLOT_COLLECTION = 'collection';
/** How photos follow the seasons – shown below every photo choice. */
public const SEASON_HINT = 'Fotos mit Saison (Webseite › Fotos › „Zeigen in“) erscheinen nur in ihrem Erscheinungsbild, alle anderen ganzjährig.';
abstract public static function key(): string;
@@ -49,16 +46,6 @@ public static function schema(): array
return [];
}
/**
* Photo places an appearance can fill with seasonal photos ("Bilder je Baustein").
*
* @return array<string, array{label: string, type: string, max?: int}>
*/
public static function photoSlots(): array
{
return [];
}
/**
* Short text identifying a placed section in admin lists, e.g. its heading.
*
@@ -108,52 +95,63 @@ protected function photos(?array $ids): Collection
}
/**
* The seasonal photo the active appearance sets for a single slot of this placed section.
* Chosen photos in the editor's order: published and fitting the season in effect.
*
* @param array<string, mixed> $data
*/
protected function seasonalPhoto(Theme $theme, array $data, string $slot): ?Photo
{
return $this->seasonalPhotos($theme, $data, $slot)?->first();
}
/**
* The seasonal photos the active appearance sets for a slot of this placed section, null if none.
*
* @param array<string, mixed> $data
* @return Collection<int, Photo>|null
*/
protected function seasonalPhotos(Theme $theme, array $data, string $slot): ?Collection
{
$ids = $theme->sectionPhotoIds($data['id'] ?? null, $slot);
if ($ids === []) {
return null;
}
$photos = $this->photos($ids);
return $photos->isEmpty() ? null : $photos;
}
/**
* Photos of a collection slot: the automatic photos, replaced or preceded by the seasonal ones.
*
* @param array<string, mixed> $data
* @param Collection<int, Photo> $automatic
* @param list<int|string>|null $ids
* @return Collection<int, Photo>
*/
protected function withSeasonalPhotos(Theme $theme, array $data, string $slot, Collection $automatic): Collection
protected function chosenPhotos(Theme $theme, ?array $ids): Collection
{
$seasonal = $this->seasonalPhotos($theme, $data, $slot);
if ($seasonal === null) {
return $automatic;
return $this->photos($ids)->filter(fn (Photo $photo): bool => $photo->fitsSeason($theme->appearance))->values();
}
/**
* Photos picked automatically for the section's apartment and the season (Photo::automatic).
*
* @return Collection<int, Photo>
*/
protected function automaticPhotos(Theme $theme, ?PhotoCategory $category = null, ?int $limit = null): Collection
{
$photos = Photo::automatic($theme->property(), $theme->appearance, $category);
return $limit !== null ? $photos->take($limit)->values() : $photos;
}
/**
* Photos of a section that offers "automatisch" or "eigene Auswahl" (fields from photoSourceFields()).
*
* @param array<string, mixed> $data
* @return Collection<int, Photo>
*/
protected function sourcedPhotos(Theme $theme, array $data, ?PhotoCategory $category = null, ?int $limit = null): Collection
{
if (($data['photo_source'] ?? 'auto') === 'selection') {
$photos = $this->chosenPhotos($theme, $data['photo_ids'] ?? []);
return $limit !== null ? $photos->take($limit)->values() : $photos;
}
if ($theme->sectionPhotoMode($data['id'] ?? null) === 'prepend') {
return $seasonal->merge($automatic)->unique('id')->values();
}
return $this->automaticPhotos($theme, $category, $limit);
}
return $seasonal;
/**
* "Automatisch" or "Eigene Auswahl" plus the selection field, shown only for a selection.
*
* @return list<Component>
*/
protected static function photoSourceFields(string $automaticLabel): array
{
return [
Radio::make('photo_source')
->label('Bilder')
->options(['auto' => $automaticLabel, 'selection' => 'Eigene Auswahl'])
->default('auto')
->inline()
->live(),
static::photoSelect('photo_ids', 'Ausgewählte Bilder', multiple: true)
->helperText(self::SEASON_HINT)
->visible(fn (Get $get): bool => $get('photo_source') === 'selection'),
];
}
protected function pageUrl(?string $slug): ?string