diff --git a/app/Domain/Cms/Sections/PageSections.php b/app/Domain/Cms/Sections/PageSections.php index 642ff0a..5fe2883 100644 --- a/app/Domain/Cms/Sections/PageSections.php +++ b/app/Domain/Cms/Sections/PageSections.php @@ -2,7 +2,9 @@ namespace App\Domain\Cms\Sections; +use App\Domain\Cms\Widgets\Support\ImageRefFields; use App\Domain\Cms\Widgets\Support\PublicMedia; +use App\Domain\Cms\Widgets\WidgetErrors; use App\Domain\Cms\Widgets\WidgetRegistry; use Illuminate\Support\Str; use Illuminate\Validation\ValidationException; @@ -145,7 +147,7 @@ public function mediaPaths(array $sections): array foreach ($sections as $section) { $style = SectionStyle::fromStored($section['style'] ?? []); - if ($style['image'] !== null && PublicMedia::isPublicPath($style['image'])) { + if (is_string($style['image']) && PublicMedia::isPublicPath($style['image'])) { $paths[] = $style['image']; } } @@ -335,14 +337,17 @@ private function normalizeStyle(array $style, string $prefix, array &$errors): a $result[$key] = $value; } - $upload = PublicMedia::fromUploadState($style['_upload'] ?? null); - $image = $upload ?? PublicMedia::fromUploadState($style['image'] ?? null); - if ($result['background'] === 'image') { - if ($image === null) { - $errors["$prefix.style.image"] = ['Bitte ein Hintergrundbild wählen oder hochladen.']; - } elseif (! PublicMedia::isPublicPath($image)) { - $errors["$prefix.style.image"] = ['Das Hintergrundbild liegt nicht im öffentlichen Medienbereich.']; + $widgetErrors = new WidgetErrors; + $refs = ImageRefFields::clean(['image' => $style['image'] ?? null, '_upload' => $style['_upload'] ?? null], $widgetErrors, errorKey: 'image'); + $image = $refs['image']; + + foreach ($widgetErrors->all() as $messages) { + $errors["$prefix.style.image"] = $messages; + } + + if ($image === null && ! isset($errors["$prefix.style.image"])) { + $errors["$prefix.style.image"] = ['Bitte ein Hintergrundbild aus dem Medienmanager wählen oder hochladen.']; } $result['image'] = $image; diff --git a/app/Domain/Cms/Sections/SectionRenderer.php b/app/Domain/Cms/Sections/SectionRenderer.php index a2ba2ee..727ea4e 100644 --- a/app/Domain/Cms/Sections/SectionRenderer.php +++ b/app/Domain/Cms/Sections/SectionRenderer.php @@ -3,7 +3,7 @@ namespace App\Domain\Cms\Sections; use App\Domain\Cms\Widgets\RenderContext; -use App\Domain\Cms\Widgets\Support\PublicMedia; +use App\Domain\Cms\Widgets\Support\WebsiteImage; use App\Domain\Cms\Widgets\WidgetRenderer; use Illuminate\Support\HtmlString; @@ -56,7 +56,7 @@ public function renderAll(array $sections, RenderContext $context): HtmlString $last = count($rendered) - 1; foreach ($rendered as $index => $item) { - $html .= $this->renderSection($item['section'], $item['cells'], $index); + $html .= $this->renderSection($item['section'], $item['cells'], $index, $context); $divider = $item['section']['style']['divider'] ?? 'none'; if ($index < $last && in_array($divider, ['line', 'accent'], true)) { @@ -71,11 +71,13 @@ public function renderAll(array $sections, RenderContext $context): HtmlString * @param array $section * @param list $cells */ - private function renderSection(array $section, array $cells, int $index): string + private function renderSection(array $section, array $cells, int $index, RenderContext $context): string { $style = SectionStyle::fromStored($section['style'] ?? []); $columns = SectionLayouts::columns(array_column($cells, 'units')); - $hasImage = $style['background'] === 'image' && $style['image'] !== null && PublicMedia::isPublicPath($style['image']); + // Hintergrundbild aus dem Medienmanager: öffentlich nur mit Website-Freigabe (WebsiteImage → WebsiteMedia). + $imageUrl = $style['background'] === 'image' ? app(WebsiteImage::class)->url($style['image'], $context->preview) : null; + $hasImage = $imageUrl !== null; $classes = [ 'page-section', @@ -109,7 +111,7 @@ private function renderSection(array $section, array $cells, int $index): string if ($hasImage) { // Das Bild des ersten Abschnitts ist meist das größte sichtbare Element und wird nicht verzögert geladen. $loading = $index === 0 ? 'loading="eager" fetchpriority="high"' : 'loading="lazy"'; - $html .= ''; } diff --git a/app/Domain/Cms/Sections/SectionStyle.php b/app/Domain/Cms/Sections/SectionStyle.php index e047be0..b968d80 100644 --- a/app/Domain/Cms/Sections/SectionStyle.php +++ b/app/Domain/Cms/Sections/SectionStyle.php @@ -2,7 +2,7 @@ namespace App\Domain\Cms\Sections; -use App\Domain\Cms\Widgets\Support\PublicMedia; +use App\Domain\Cms\Widgets\Support\WebsiteImage; /** * Semantische Abschnittsgestaltung. Jeder Wert ist eine Aufzählung, die auf zentrale Design-Tokens @@ -134,7 +134,7 @@ public static function fromStored(mixed $style): array } } - $result['image'] = $result['background'] === 'image' && is_string($style['image'] ?? null) ? $style['image'] : null; + $result['image'] = $result['background'] === 'image' ? WebsiteImage::normalize($style['image'] ?? null) : null; return $result; } @@ -204,7 +204,7 @@ public static function migrateSpacing(array $sections, bool $byVersion = false): $rendered = is_array($section['slots'] ?? null) && array_filter($section['slots'], 'is_array') !== []; $background = is_string($style['background'] ?? null) && isset(self::BACKGROUNDS[$style['background']]) ? $style['background'] : 'default'; - if ($background === 'image' && ! PublicMedia::isPublicPath($style['image'] ?? null)) { + if ($background === 'image' && WebsiteImage::normalize($style['image'] ?? null) === null) { $background = 'default'; } $divider = in_array($style['divider'] ?? null, ['line', 'accent'], true) ? $style['divider'] : 'none'; diff --git a/app/Domain/Cms/WebsiteImageUsage.php b/app/Domain/Cms/WebsiteImageUsage.php new file mode 100644 index 0000000..b9c9463 --- /dev/null +++ b/app/Domain/Cms/WebsiteImageUsage.php @@ -0,0 +1,56 @@ + + */ + public function pages(ContentElement $element): array + { + $legacy = WebsiteMediaAlias::query()->where('content_element_id', $element->id)->pluck('legacy_path')->all(); + $usages = []; + + foreach (Page::query()->with(['publishedRevision', 'latestRevision'])->orderBy('path')->get() as $page) { + $published = $page->publishedRevision !== null && $this->uses($page->publishedRevision->sections ?? [], $element->id, $legacy); + $draft = $page->latestRevision !== null && $page->latestRevision->id !== $page->published_revision_id + && $this->uses($page->latestRevision->sections ?? [], $element->id, $legacy); + + if ($published || $draft) { + $usages[] = ['path' => (string) $page->path, 'published' => $published, 'draft' => $draft]; + } + } + + return $usages; + } + + /** + * @param list $legacy + */ + private function uses(mixed $value, int $id, array $legacy): bool + { + if (! is_array($value)) { + return false; + } + + foreach ($value as $key => $item) { + if ($key === 'image' && (($item === $id || (is_string($item) && ($item === (string) $id || in_array($item, $legacy, true)))))) { + return true; + } + + if (is_array($item) && $this->uses($item, $id, $legacy)) { + return true; + } + } + + return false; + } +} diff --git a/app/Domain/Cms/Widgets/Support/ImageRefFields.php b/app/Domain/Cms/Widgets/Support/ImageRefFields.php index d5244a6..ca47880 100644 --- a/app/Domain/Cms/Widgets/Support/ImageRefFields.php +++ b/app/Domain/Cms/Widgets/Support/ImageRefFields.php @@ -5,40 +5,80 @@ use App\Domain\Cms\Widgets\WidgetErrors; use Filament\Forms\Components\Field; use Filament\Forms\Components\FileUpload; +use Filament\Forms\Components\Placeholder; use Filament\Forms\Components\Select; -use Illuminate\Support\Str; +use Filament\Notifications\Notification; +use Filament\Schemas\Components\Utilities\Get; +use Filament\Schemas\Components\Utilities\Set; +use Illuminate\Support\HtmlString; use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; /** - * Gemeinsame Bildauswahl für Widgets: vorhandenes Bild aus dem öffentlichen Website-Bereich wählen - * oder ein neues hochladen. Keine eigene Medienverwaltung. + * Gemeinsame Bildauswahl aller Widgets und des Abschnittshintergrunds: Bilder aus dem zentralen Medienmanager + * (siehe WebsiteImage, docs/architektur/medienzugriff-fuer-komponenten.md). Keine eigene CMS-Medienverwaltung. + * + * - Auswahl: durchsuchbare Liste mit Vorschaubild, Titel und Website-Status. + * - Neu hochladen: Das Bild wird sofort als Medium im Medienmanager angelegt (WebsiteIntake) und ausgewählt. + * - Anzeige des gewählten Mediums mit Status und Verweis auf die Freigabe im Medienmanager. + * + * Das Bedienmuster folgt der Bildauswahl im Modul- und Programmeditor (Suche, Vorschaubild, Auswählen); jene ist an + * die Livewire-Seite des Editors gebunden und lässt sich nicht als Formularfeld im Widget-Dialog einhängen. */ final class ImageRefFields { /** * @param bool $live Änderungen sofort an die Vorschau im Bearbeitungsdialog geben. - * @return list + * @param string|null $altField Name des Alternativtext-Felds im selben Formular (für neue Medien), falls vorhanden. + * @return list */ - public static function fields(string $label = 'Bild', bool $live = false): array + public static function fields(string $label = 'Bild', bool $live = false, string $key = 'image', ?string $altField = null): array { return [ - Select::make('image') - ->live($live) - ->label($label.': vorhandenes Bild') - ->options(fn (): array => PublicMedia::imageOptions()) + Select::make($key) + ->live() + ->label($label.' aus dem Medienmanager') ->searchable() + ->allowHtml() + ->options(fn (): array => app(WebsiteImage::class)->options()) + ->getSearchResultsUsing(fn (?string $search): array => app(WebsiteImage::class)->options($search)) + ->getOptionLabelUsing(fn (mixed $value): ?string => app(WebsiteImage::class)->optionHtml($value)) ->placeholder('Kein Bild') - ->helperText('Auswahl aus den Bildern, die bereits für die Website hochgeladen wurden.'), + ->helperText('Alle Bilder des Medienmanagers. Öffentlich erscheint ein Bild nur mit Website-Freigabe.'), FileUpload::make('_upload') - ->live($live) - ->label($label.': neu hochladen') - ->disk('cms_incoming') - ->directory('cms') + ->live() + ->label($label.': neues Bild hochladen') ->image() ->maxSize(8192) ->acceptedFileTypes(['image/jpeg', 'image/png', 'image/webp']) - ->getUploadedFileNameForStorageUsing(fn (TemporaryUploadedFile $file): string => Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)).'-'.Str::lower(Str::random(6)).'.'.$file->guessExtension()) - ->helperText('Ein neues Bild ersetzt die Auswahl oben. Es wird beim Speichern im öffentlichen Bereich der Website abgelegt.'), + ->storeFiles(false) + ->afterStateUpdated(function (mixed $state, Set $set, Get $get) use ($key, $altField): void { + $file = is_array($state) ? (array_values($state)[0] ?? null) : $state; + + if (! $file instanceof TemporaryUploadedFile) { + return; + } + + $element = app(WebsiteImage::class)->accept($file, $altField !== null ? $get($altField) : null); + $set('_upload', null); + + if ($element === null) { + Notification::make()->danger()->title('Das Bild konnte nicht übernommen werden.')->send(); + + return; + } + + $set($key, $element->id); + Notification::make() + ->success() + ->title('Im Medienmanager angelegt: „'.($element->display_title ?: $element->working_title).'“') + ->body('Das Bild ist ausgewählt. Nach der Verarbeitung wird es automatisch für die Website freigegeben.') + ->send(); + }) + ->helperText('Das Bild wird im Medienmanager angelegt und hier ausgewählt. Nur Bilder mit geklärten Rechten hochladen.'), + Placeholder::make('_media_status') + ->label('Gewähltes Bild') + ->visible(fn (Get $get): bool => WebsiteImage::normalize($get($key)) !== null) + ->content(fn (Get $get): HtmlString => self::statusHtml($get($key))), ]; } @@ -48,29 +88,49 @@ public static function fields(string $label = 'Bild', bool $live = false): array public static function rules(): array { return [ - 'image' => ['nullable', 'string', 'max:255'], + 'image' => ['nullable'], '_upload' => ['nullable'], ]; } /** - * Übernimmt einen neuen Upload als Bild und prüft, dass das Bild im öffentlichen Bereich liegt. + * Prüft das gewählte Bild. Ein früherer CMS-Pfad mit wirksamer Zuordnung wird zur Kennung des Mediums. + * Ein noch als Datei übergebener Upload (frühere Formulare) wird über den Medienmanager aufgenommen. * * @param array $refs * @return array */ public static function clean(array $refs, WidgetErrors $errors, string $key = 'image', ?string $errorKey = null): array { - $upload = PublicMedia::fromUploadState($refs['_upload'] ?? null); - $image = $upload ?? PublicMedia::fromUploadState($refs[$key] ?? null); + $images = app(WebsiteImage::class); + $upload = $refs['_upload'] ?? null; + $upload = is_array($upload) ? (array_values($upload)[0] ?? null) : $upload; - if ($image !== null && ! PublicMedia::isPublicPath($image)) { - $errors->add($errorKey ?? "refs.$key", 'Das Bild liegt nicht im öffentlichen Medienbereich.'); + if ($upload instanceof TemporaryUploadedFile) { + $element = $images->accept($upload); + $refs[$key] = $element?->id ?? $refs[$key] ?? null; } - $refs[$key] = $image; + $refs[$key] = $images->clean($refs[$key] ?? null, $errors, $errorKey ?? "refs.$key"); unset($refs['_upload']); return $refs; } + + public static function statusHtml(mixed $value): HtmlString + { + $status = app(WebsiteImage::class)->status($value); + + if ($status === null) { + return new HtmlString(''); + } + + $thumb = $status['thumb'] !== null ? '' : ''; + $link = $status['manageUrl'] !== null + ? 'Im Medienmanager öffnen' + : ''; + + return new HtmlString('
'.$thumb + .'
'.e($status['title']).'

'.e($status['note']).'

'.$link.'
'); + } } diff --git a/app/Domain/Cms/Widgets/Support/PremiumFields.php b/app/Domain/Cms/Widgets/Support/PremiumFields.php index d1b8cb4..ca65e38 100644 --- a/app/Domain/Cms/Widgets/Support/PremiumFields.php +++ b/app/Domain/Cms/Widgets/Support/PremiumFields.php @@ -98,10 +98,10 @@ public static function focusFields(int $defaultX = 50, int $defaultY = 50): arra public static function altField(): TextInput { return TextInput::make('alt') - ->label('Alternativtext des Bildes') + ->label('Alternativtext (optional)') ->maxLength(300) ->live(onBlur: true) - ->helperText('Beschreibt, was auf dem Bild zu sehen ist. Pflicht, sobald ein Bild gewählt ist.'); + ->helperText('Leer lassen, dann gilt der Alternativtext des Mediums aus dem Medienmanager. Nur ausfüllen, wenn das Bild hier etwas anderes aussagen soll.'); } /** @@ -127,10 +127,6 @@ public static function clean(array $data, WidgetErrors $errors, bool $hasImage): $data[$key] = is_numeric($value) ? (int) round(max(0, min(100, (float) $value))) : null; } - if ($hasImage && $data['alt'] === null) { - $errors->add('data.alt', 'Bitte einen Alternativtext für das Bild angeben.'); - } - return $data; } diff --git a/app/Domain/Cms/Widgets/Support/PublicMedia.php b/app/Domain/Cms/Widgets/Support/PublicMedia.php index 4984750..b161b86 100644 --- a/app/Domain/Cms/Widgets/Support/PublicMedia.php +++ b/app/Domain/Cms/Widgets/Support/PublicMedia.php @@ -2,20 +2,14 @@ namespace App\Domain\Cms\Widgets\Support; -use Illuminate\Support\Facades\Storage; -use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; -use Throwable; - /** - * Öffentlicher Medienbereich der Website ("cms/"). Nur Dateien aus diesem Bereich dürfen in Widgets - * verwendet werden. Geschützte Bibliotheksmedien (Inhaltsdateien, Vorschaubilder) sind hier nie wählbar. + * Frühere öffentliche CMS-Bilder („cms/“, Route media.public). Neue Bilder kommen aus dem Medienmanager (WebsiteImage); + * dieser Bereich bleibt nur für gespeicherte Revisionen mit früheren Pfaden, die (noch) keinem Medium zugeordnet sind. */ final class PublicMedia { public const PREFIX = 'cms/'; - private const IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'webp', 'gif', 'avif']; - public static function isPublicPath(mixed $path): bool { return is_string($path) @@ -29,36 +23,6 @@ public static function url(string $path): string return route('media.public', ['path' => $path]); } - /** - * Bereits vorhandene Bilder im öffentlichen Bereich (veröffentlicht oder zur Veröffentlichung vorgemerkt). - * - * @return array - */ - public static function imageOptions(): array - { - $options = []; - - foreach (['media_public', 'cms_incoming'] as $disk) { - try { - $files = Storage::disk($disk)->allFiles(rtrim(self::PREFIX, '/')); - } catch (Throwable) { - $files = []; - } - - foreach ($files as $file) { - $extension = strtolower(pathinfo($file, PATHINFO_EXTENSION)); - - if (self::isPublicPath($file) && in_array($extension, self::IMAGE_EXTENSIONS, true)) { - $options[$file] = substr($file, strlen(self::PREFIX)); - } - } - } - - ksort($options); - - return $options; - } - /** * Pfad aus dem Zustand eines Upload-Felds (Zeichenkette oder Liste). */ @@ -70,31 +34,4 @@ public static function fromUploadState(mixed $state): ?string return is_string($state) && $state !== '' ? $state : null; } - - /** - * Bildadresse für Darstellung und Blockvorschau. In der Vorschau kann ein noch nicht gespeicherter Upload vorliegen. - * - * @param array $refs - */ - public static function imageUrl(array $refs, string $key = 'image'): ?string - { - $upload = $refs['_upload'] ?? null; - $upload = is_array($upload) ? (array_values($upload)[0] ?? null) : $upload; - - if ($upload instanceof TemporaryUploadedFile) { - try { - return $upload->temporaryUrl(); - } catch (Throwable) { - return null; - } - } - - if (self::isPublicPath($upload)) { - return self::url($upload); - } - - $path = $refs[$key] ?? null; - - return self::isPublicPath($path) ? self::url($path) : null; - } } diff --git a/app/Domain/Cms/Widgets/Support/WebsiteImage.php b/app/Domain/Cms/Widgets/Support/WebsiteImage.php new file mode 100644 index 0000000..61b5a15 --- /dev/null +++ b/app/Domain/Cms/Widgets/Support/WebsiteImage.php @@ -0,0 +1,349 @@ + */ + private array $resolved = []; + + /** @var array */ + private array $presentations = []; + + public function __construct(private readonly WebsiteMedia $media) {} + + /** + * Gespeicherter oder eingegebener Wert → Kennung (int), früherer Pfad (string) oder null. + */ + public static function normalize(mixed $value): int|string|null + { + if (is_array($value)) { + $value = array_values($value)[0] ?? null; + } + + if (is_int($value) && $value > 0) { + return $value; + } + + if (is_string($value) && preg_match('/^[1-9][0-9]*$/', $value) === 1) { + return (int) $value; + } + + return PublicMedia::isPublicPath($value) ? $value : null; + } + + /** + * Kennung des Mediums: gespeicherte Kennung oder wirksam zugeordneter früherer Pfad; sonst null. + */ + public function elementId(mixed $value): ?int + { + $value = self::normalize($value); + + if (is_int($value)) { + return $value; + } + + if ($value === null) { + return null; + } + + if (! array_key_exists($value, $this->resolved)) { + $this->resolved[$value] = WebsiteMediaAlias::effectiveFor($value)?->content_element_id; + } + + $id = $this->resolved[$value]; + + return is_int($id) ? $id : null; + } + + public function presentation(mixed $value): ?WebsitePresentation + { + $id = $this->elementId($value); + + if ($id === null) { + return null; + } + + if (! array_key_exists($id, $this->presentations)) { + $this->presentations[$id] = $this->media->present($id) ?? false; + } + + return $this->presentations[$id] ?: null; + } + + /** + * Bildadresse für die Darstellung. Öffentlich nur freigegebene Medien (oder frühere CMS-Bilder ohne Zuordnung); + * in der Redaktionsvorschau zusätzlich das Vorschaubild eines nicht freigegebenen Mediums. + */ + public function url(mixed $value, bool $preview = false): ?string + { + $presentation = $this->presentation($value); + + if ($presentation !== null) { + return $presentation->kind === 'bild' ? $presentation->url : null; + } + + $id = $this->elementId($value); + + if ($id !== null) { + if (! $preview) { + return null; + } + + $element = ContentElement::query()->find($id); + + return $element === null ? null : ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path); + } + + $legacy = self::normalize($value); + + return is_string($legacy) ? PublicMedia::url($legacy) : null; + } + + /** Alternativtext: Angabe im Widget, sonst der Alternativtext des Mediums. */ + public function alt(mixed $value, mixed $override = null): string + { + if (is_string($override) && trim($override) !== '') { + return trim($override); + } + + return $this->presentation($value)?->alt ?? ''; + } + + /** Öffentliche Quellenzeile des Mediums (nur solange es freigegeben ist). */ + public function credit(mixed $value): ?string + { + return $this->presentation($value)?->credit; + } + + /** + * Hinweis für die Redaktionsvorschau, wenn das gewählte Bild öffentlich nicht erscheint; sonst null. + */ + public function previewNotice(mixed $value, string $label = 'Das gewählte Bild'): ?string + { + $status = $this->status($value); + + if ($status === null || $status['public']) { + return null; + } + + return $label.' „'.$status['title'].'“ erscheint öffentlich nicht: '.$status['note']; + } + + /** + * Zustand für Editor und Vorschau. + * + * @return array{public: bool, state: string, title: string, note: string, thumb: ?string, manageUrl: ?string}|null + */ + public function status(mixed $value): ?array + { + $value = self::normalize($value); + + if ($value === null) { + return null; + } + + $id = $this->elementId($value); + + if ($id === null) { + return [ + 'public' => true, + 'state' => 'legacy', + 'title' => basename((string) $value), + 'note' => 'Früheres CMS-Bild, noch nicht in den Medienmanager übernommen.', + 'thumb' => PublicMedia::url((string) $value), + 'manageUrl' => null, + ]; + } + + $element = ContentElement::query()->with('editorialContentKind')->find($id); + + if ($element === null) { + return ['public' => false, 'state' => 'missing', 'title' => 'Medium '.$id, 'note' => 'Das Medium gibt es nicht mehr.', 'thumb' => null, 'manageUrl' => null]; + } + + $title = (string) ($element->display_title ?: $element->working_title); + $thumb = ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path); + $manageUrl = ContentElementResource::getUrl('view', ['record' => $element]); + $public = $this->presentation($id) !== null; + + $note = match (true) { + $public => 'Für die Website freigegeben.', + $element->archived_at !== null => 'Das Medium ist archiviert.', + filled($element->thumbnail_error) => 'Die Datei ließ sich nicht verarbeiten: '.Str::limit((string) $element->thumbnail_error, 120), + $element->thumbnail_path === null => 'Wird gerade verarbeitet. Danach wird es automatisch für die Website freigegeben.', + default => 'Nicht für die Website freigegeben. Die Freigabe steht im Medienmanager beim Medium unter „Beschreibung“ (Website-Freigabe).', + }; + + return [ + 'public' => $public, + 'state' => $public ? 'released' : ($element->thumbnail_path === null && ! filled($element->thumbnail_error) ? 'pending' : 'unreleased'), + 'title' => $title, + 'note' => $note, + 'thumb' => $thumb, + 'manageUrl' => $manageUrl, + ]; + } + + /** + * Prüft einen Wert beim Speichern. Ein früherer Pfad mit wirksamer Zuordnung wird zur Kennung des Mediums. + */ + public function clean(mixed $value, WidgetErrors $errors, string $errorKey): int|string|null + { + $raw = is_array($value) ? (array_values($value)[0] ?? null) : $value; + $value = self::normalize($raw); + + if ($value === null) { + if ($raw !== null && $raw !== '') { + $errors->add($errorKey, 'Bitte ein Bild aus dem Medienmanager wählen.'); + } + + return null; + } + + if (is_string($value)) { + return $this->elementId($value) ?? $value; + } + + $element = ContentElement::query()->find($value); + + if ($element === null || ! self::isSelectable($element)) { + $errors->add($errorKey, 'Dieses Medium ist kein Bild für die Website (nur Bilder aus dem Medienmanager, keine Traineranleitungen).'); + + return null; + } + + return $element->id; + } + + public static function isSelectable(ContentElement $element): bool + { + if ($element->output_class !== 'bild' || $element->archived_at !== null) { + return false; + } + + $slug = $element->editorialContentKind?->slug + ?? ($element->editorial_content_kind_id !== null ? EditorialContentKind::query()->whereKey($element->editorial_content_kind_id)->value('slug') : null); + + return ! in_array($slug, PublicMaterialReader::CONFIDENTIAL_KINDS, true); + } + + /** + * Auswahl für den Medienpicker: Bilder aus dem Medienmanager mit Vorschaubild, Titel und Freigabestatus (HTML). + * + * @return array + */ + public function options(?string $search = null, int $limit = 60): array + { + $search = trim((string) $search); + + $elements = ContentElement::query() + ->with('editorialContentKind') + ->where('output_class', 'bild') + ->whereNull('archived_at') + ->when($search !== '', function ($query) use ($search): void { + $like = '%'.mb_strtolower($search).'%'; + $query->where(fn ($inner) => $inner + ->whereRaw('LOWER(working_title) LIKE ?', [$like]) + ->orWhereRaw('LOWER(COALESCE(display_title, \'\')) LIKE ?', [$like])); + }) + ->orderByDesc('id') + ->limit($limit) + ->get(); + + $options = []; + foreach ($elements as $element) { + if (self::isSelectable($element)) { + $options[$element->id] = $this->optionHtml($element->id); + } + } + + return $options; + } + + /** HTML-Bezeichnung einer Option oder des gewählten Werts (auch für frühere Pfade). */ + public function optionHtml(mixed $value): ?string + { + $status = $this->status($value); + + if ($status === null) { + return null; + } + + $badge = match ($status['state']) { + 'released' => ['ok', 'Website: freigegeben'], + 'pending' => ['wait', 'Wird verarbeitet'], + 'legacy' => ['quiet', 'Früheres CMS-Bild'], + default => ['warn', 'Website: nicht freigegeben'], + }; + $thumb = $status['thumb'] !== null + ? '' + : ''; + + return ''.$thumb + .''.e($status['title']).'' + .''.e($badge[1]).''; + } + + /** + * Neues Bild direkt aus dem CMS: Datei in den Eingang legen und über WebsiteIntake als Medium anlegen. + * Die Warteschlange leitet das Bild ab und gibt die Ableitung für die Website frei. + */ + public function accept(TemporaryUploadedFile $file, ?string $alt = null): ?ContentElement + { + $base = Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)) ?: 'bild'; + $name = $base.'-'.Str::lower(Str::random(6)).'.'.($file->guessExtension() ?: 'jpg'); + + try { + $path = $file->storeAs('cms', $name, 'cms_incoming'); + } catch (Throwable $exception) { + report($exception); + + return null; + } + + if (! is_string($path) || $path === '') { + return null; + } + + $actor = auth('staff')->user(); + + return app(WebsiteIntake::class)->acceptImage( + $path, + Str::title(str_replace(['-', '_'], ' ', $base)), + null, + filled($alt) ? trim((string) $alt) : null, + $actor instanceof User ? $actor : null, + ); + } +} diff --git a/app/Domain/Cms/Widgets/Types/CardsWidget.php b/app/Domain/Cms/Widgets/Types/CardsWidget.php index cc3bd86..0c54bea 100644 --- a/app/Domain/Cms/Widgets/Types/CardsWidget.php +++ b/app/Domain/Cms/Widgets/Types/CardsWidget.php @@ -6,6 +6,7 @@ use App\Domain\Cms\Widgets\Support\ImageRefFields; use App\Domain\Cms\Widgets\Support\PublicMedia; use App\Domain\Cms\Widgets\Support\SafeUrl; +use App\Domain\Cms\Widgets\Support\WebsiteImage; use App\Domain\Cms\Widgets\WidgetErrors; use App\Domain\Cms\Widgets\WidgetType; use Filament\Forms\Components\Repeater; @@ -84,14 +85,14 @@ public function dataRules(): array 'items.*.title' => ['required', 'string', 'max:120'], 'items.*.text' => ['nullable', 'string', 'max:500'], 'items.*.url' => ['nullable', 'string', 'max:500'], - 'items.*.image' => ['nullable', 'string', 'max:255'], + 'items.*.image' => ['nullable'], 'items.*._upload' => ['nullable'], ]; } public function dataFields(): array { - [$image, $upload] = ImageRefFields::fields('Bild (optional)'); + [$image, $upload, $status] = ImageRefFields::fields('Bild (optional)'); return [ Repeater::make('items') @@ -106,6 +107,7 @@ public function dataFields(): array ->helperText('Seitenpfad wie /praevention oder eine http(s)-Adresse. Leer lassen für eine Karte ohne Link.'), $image, $upload, + $status, ]) ->minItems(1) ->maxItems(12) @@ -139,7 +141,9 @@ public function clean(array $data, array $refs, WidgetErrors $errors): array public function resolve(array $widget, RenderContext $context): array { + $images = app(WebsiteImage::class); $items = []; + $notices = []; foreach ($widget['data']['items'] ?? [] as $item) { if (! is_array($item) || ! filled($item['title'] ?? null)) { @@ -150,11 +154,15 @@ public function resolve(array $widget, RenderContext $context): array 'title' => $item['title'], 'text' => $item['text'] ?? null, 'url' => SafeUrl::isSafe($item['url'] ?? null) ? $item['url'] : null, - 'imageUrl' => PublicMedia::imageUrl($item), + 'imageUrl' => $images->url($item['image'] ?? null, $context->preview), ]; + + if ($context->preview && ($notice = $images->previewNotice($item['image'] ?? null, 'Das Bild der Karte „'.$item['title'].'“')) !== null) { + $notices[] = $notice; + } } - return ['items' => $items]; + return ['items' => $items, 'imageNotice' => $notices === [] ? null : implode(' ', $notices)]; } public function mediaPaths(array $widget): array diff --git a/app/Domain/Cms/Widgets/Types/HeroWidget.php b/app/Domain/Cms/Widgets/Types/HeroWidget.php index 01b7ed7..ad02d15 100644 --- a/app/Domain/Cms/Widgets/Types/HeroWidget.php +++ b/app/Domain/Cms/Widgets/Types/HeroWidget.php @@ -6,6 +6,7 @@ use App\Domain\Cms\Widgets\Support\ImageRefFields; use App\Domain\Cms\Widgets\Support\PremiumFields; use App\Domain\Cms\Widgets\Support\PublicMedia; +use App\Domain\Cms\Widgets\Support\WebsiteImage; use App\Domain\Cms\Widgets\WidgetErrors; use App\Domain\Cms\Widgets\WidgetType; use Filament\Forms\Components\Textarea; @@ -202,8 +203,13 @@ public function resolve(array $widget, RenderContext $context): array { $actions = PremiumFields::actions($widget['data']); + $images = app(WebsiteImage::class); + $image = $widget['refs']['image'] ?? null; + return [ - 'imageUrl' => PublicMedia::imageUrl($widget['refs']), + 'imageUrl' => $images->url($image, $context->preview), + 'imageAlt' => $images->alt($image, $widget['data']['alt'] ?? null), + 'imageNotice' => $context->preview ? $images->previewNotice($image) : null, 'actions' => $actions, 'action' => $actions[0] ?? null, 'focus' => PremiumFields::focus($widget['data'], 68, 50), diff --git a/app/Domain/Cms/Widgets/Types/ImageTextWidget.php b/app/Domain/Cms/Widgets/Types/ImageTextWidget.php index 98149e7..f26ef3f 100644 --- a/app/Domain/Cms/Widgets/Types/ImageTextWidget.php +++ b/app/Domain/Cms/Widgets/Types/ImageTextWidget.php @@ -7,6 +7,7 @@ use App\Domain\Cms\Widgets\Support\PremiumFields; use App\Domain\Cms\Widgets\Support\PublicMedia; use App\Domain\Cms\Widgets\Support\RichText; +use App\Domain\Cms\Widgets\Support\WebsiteImage; use App\Domain\Cms\Widgets\WidgetErrors; use App\Domain\Cms\Widgets\WidgetType; use Filament\Forms\Components\RichEditor; @@ -229,8 +230,13 @@ public function resolve(array $widget, RenderContext $context): array { $surface = $widget['settings']['surface'] ?? 'cream'; + $images = app(WebsiteImage::class); + $image = $widget['refs']['image'] ?? null; + return [ - 'imageUrl' => PublicMedia::imageUrl($widget['refs']), + 'imageUrl' => $images->url($image, $context->preview), + 'imageAlt' => $images->alt($image, $widget['data']['alt'] ?? null), + 'imageNotice' => $context->preview ? $images->previewNotice($image) : null, 'body' => RichText::sanitize(is_string($widget['data']['body'] ?? null) ? $widget['data']['body'] : ''), 'actions' => PremiumFields::actions($widget['data']), 'focus' => PremiumFields::focus($widget['data'], 64, 43), diff --git a/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php b/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php index 1d66939..5986c57 100644 --- a/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php +++ b/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php @@ -7,6 +7,7 @@ use App\Domain\Cms\Widgets\Support\ImageRefFields; use App\Domain\Cms\Widgets\Support\PremiumFields; use App\Domain\Cms\Widgets\Support\PublicMedia; +use App\Domain\Cms\Widgets\Support\WebsiteImage; use App\Domain\Cms\Widgets\WidgetErrors; use App\Domain\Cms\Widgets\WidgetType; use Filament\Forms\Components\Select; @@ -213,10 +214,6 @@ public function clean(array $data, array $refs, WidgetErrors $errors): array $data[$field] = is_numeric($value) ? (int) round(max(0, min(100, (float) $value))) : null; } - if ($refs['image'] !== null && $data['alt'] === null) { - $errors->add('data.alt', 'Bitte einen Alternativtext für das Bild angeben.'); - } - return [$data, $refs]; } @@ -231,8 +228,9 @@ public function resolve(array $widget, RenderContext $context): array return [ 'subject' => $subject, 'cardStyle' => $subject?->style ?? $this->cardStyle(), - 'imageUrl' => PublicMedia::imageUrl($widget['refs']), - 'alt' => is_string($data['alt'] ?? null) ? $data['alt'] : '', + 'imageUrl' => app(WebsiteImage::class)->url($widget['refs']['image'] ?? null, $context->preview), + 'alt' => app(WebsiteImage::class)->alt($widget['refs']['image'] ?? null, $data['alt'] ?? null), + 'imageNotice' => $context->preview ? app(WebsiteImage::class)->previewNotice($widget['refs']['image'] ?? null, 'Das Kartenbild') : null, 'focus' => PremiumFields::focus($data, 66, 45), 'format' => $option('format', 'landscape'), 'fit' => $option('fit', 'cover'), diff --git a/app/Domain/Media/WebsiteMediaAlias.php b/app/Domain/Media/WebsiteMediaAlias.php new file mode 100644 index 0000000..6d9adca --- /dev/null +++ b/app/Domain/Media/WebsiteMediaAlias.php @@ -0,0 +1,59 @@ +belongsTo(ContentElement::class, 'content_element_id'); + } + + /** + * Wirksame Zuordnung für einen früheren Pfad, sonst null. Zwischengespeichert wird im Aufrufer (WebsiteImage, je Anfrage). + */ + public static function effectiveFor(mixed $path): ?self + { + if (! is_string($path) || $path === '') { + return null; + } + + $alias = self::query()->with('element')->where('legacy_path', $path)->first(); + + return $alias instanceof self && $alias->everReleased() ? $alias : null; + } + + public function everReleased(): bool + { + $element = $this->element; + + if ($element === null) { + return false; + } + + if ($element->website_released_at !== null) { + return true; + } + + return IdentityChange::query() + ->where('subject_type', $element->getMorphClass()) + ->where('subject_id', $element->id) + ->where('field', 'website_released_at') + ->whereNotNull('after') + ->exists(); + } +} diff --git a/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php index cbe8e8d..79898e0 100644 --- a/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php +++ b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php @@ -13,6 +13,7 @@ use App\Domain\Catalog\IdentityProfile; use App\Domain\Catalog\PillarService; use App\Domain\Cms\Catalog\PublicMaterialReader; +use App\Domain\Cms\WebsiteImageUsage; use App\Domain\Cms\Widgets\RenderContext; use App\Domain\Media\ThumbnailRef; use App\Domain\Media\WebsiteMedia; @@ -513,6 +514,19 @@ public function withdrawWebsite(): void $this->fillEditorial(); } + /** + * Website-Seiten, die dieses Medium als Bild verwenden (CMS-Widgets und Abschnittshintergründe). + * + * @return list + */ + public function websitePages(): array + { + /** @var ContentElement $element */ + $element = $this->getRecord(); + + return app(WebsiteImageUsage::class)->pages($element); + } + public function websiteIsPublic(): bool { /** @var ContentElement $element */ diff --git a/app/Filament/Support/SectionEditor.php b/app/Filament/Support/SectionEditor.php index 9ae3e11..e22a0ad 100644 --- a/app/Filament/Support/SectionEditor.php +++ b/app/Filament/Support/SectionEditor.php @@ -5,10 +5,9 @@ use App\Domain\Cms\Sections\PageSections; use App\Domain\Cms\Sections\SectionLayouts; use App\Domain\Cms\Sections\SectionStyle; -use App\Domain\Cms\Widgets\Support\PublicMedia; +use App\Domain\Cms\Widgets\Support\ImageRefFields; use App\Domain\Cms\Widgets\WidgetRegistry; use Filament\Actions\Action; -use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\Hidden; use Filament\Forms\Components\Repeater; use Filament\Forms\Components\Select; @@ -20,7 +19,6 @@ use Filament\Schemas\Components\Utilities\Set; use Illuminate\Support\HtmlString; use Illuminate\Support\Str; -use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; /** * Seiteneditor für Abschnitte und Slots. @@ -166,25 +164,10 @@ private static function styleFields(): array ->options(SectionStyle::DIVIDERS) ->default('none') ->selectablePlaceholder(false), - Select::make('image') - ->label('Hintergrundbild: vorhandenes Bild') - ->options(fn (): array => PublicMedia::imageOptions()) - ->searchable() - ->placeholder('Bitte wählen') - ->helperText('Nur Bilder aus dem öffentlichen Website-Bereich. Geschützte Filmbilder sind hier nicht wählbar.') - ->visible(fn (Get $get): bool => $get('background') === 'image') - ->columnSpan(['default' => 1, 'md' => 2]), - FileUpload::make('_upload') - ->label('Hintergrundbild: neu hochladen') - ->disk('cms_incoming') - ->directory('cms') - ->image() - ->maxSize(8192) - ->acceptedFileTypes(['image/jpeg', 'image/png', 'image/webp']) - ->getUploadedFileNameForStorageUsing(fn (TemporaryUploadedFile $file): string => Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)).'-'.Str::lower(Str::random(6)).'.'.$file->guessExtension()) - ->helperText('Ersetzt die Auswahl links. Nur Bilder mit geklärter Veröffentlichungsfreigabe hochladen.') - ->visible(fn (Get $get): bool => $get('background') === 'image') - ->columnSpan(['default' => 1, 'md' => 2]), + ...array_map( + fn ($field) => $field->visible(fn (Get $get): bool => $get('background') === 'image')->columnSpan(['default' => 1, 'md' => 2]), + ImageRefFields::fields('Hintergrundbild'), + ), Select::make('focus') ->label('Bildausschnitt (Fokuspunkt)') ->options(SectionStyle::FOCUS) diff --git a/app/Http/Controllers/PublicMediaController.php b/app/Http/Controllers/PublicMediaController.php index 1b35ad9..7004511 100644 --- a/app/Http/Controllers/PublicMediaController.php +++ b/app/Http/Controllers/PublicMediaController.php @@ -2,15 +2,21 @@ namespace App\Http\Controllers; +use App\Domain\Media\WebsiteMedia; +use App\Domain\Media\WebsiteMediaAlias; use Illuminate\Support\Facades\Storage; use Symfony\Component\HttpFoundation\StreamedResponse; class PublicMediaController extends Controller { - public function show(string $path): StreamedResponse + public function show(string $path, WebsiteMedia $media): StreamedResponse { abort_if(str_contains($path, '..') || ! str_starts_with($path, 'cms/'), 404); + // Ein in den Medienmanager übernommenes Bild folgt dessen Website-Freigabe, auch unter der früheren Adresse. + $alias = WebsiteMediaAlias::effectiveFor($path); + abort_if($alias !== null && $media->present($alias->content_element_id) === null, 404); + foreach (['media_public', 'cms_incoming'] as $disk) { if (Storage::disk($disk)->exists($path)) { return Storage::disk($disk)->response($path); diff --git a/app/Jobs/ImportCmsImages.php b/app/Jobs/ImportCmsImages.php new file mode 100644 index 0000000..724b7ad --- /dev/null +++ b/app/Jobs/ImportCmsImages.php @@ -0,0 +1,83 @@ +allFiles('cms'); + } catch (Throwable) { + return; + } + + sort($files); + + foreach ($files as $path) { + if (! $this->isImage($path) || WebsiteMediaAlias::query()->where('legacy_path', $path)->exists()) { + continue; + } + + $bytes = $public->get($path); + + if (! is_string($bytes) || $bytes === '') { + continue; + } + + $hash = hash('sha256', $bytes); + $twin = WebsiteMediaAlias::query()->where('sha256', $hash)->first(); + + if ($twin instanceof WebsiteMediaAlias) { + WebsiteMediaAlias::query()->create(['legacy_path' => $path, 'content_element_id' => $twin->content_element_id, 'sha256' => $hash]); + + continue; + } + + Storage::disk('cms_incoming')->put($path, $bytes); + $element = $intake->acceptImage($path, self::titleFor($path)); + WebsiteMediaAlias::query()->create(['legacy_path' => $path, 'content_element_id' => $element->id, 'sha256' => $hash]); + } + } + + /** „cms/platzhalter-karte-1-liyjqa.jpg“ → „Platzhalter Karte 1“ (ohne die angehängte Zufallskennung). */ + public static function titleFor(string $path): string + { + $name = pathinfo($path, PATHINFO_FILENAME); + $name = preg_replace('/-[a-z0-9]{6}$/', '', $name) ?? $name; + $title = trim(str_replace(['-', '_'], ' ', $name)); + + return $title === '' ? 'Website-Bild' : Str::title($title); + } + + private function isImage(string $path): bool + { + return str_starts_with($path, 'cms/') + && ! str_contains($path, '..') + && preg_match('#^cms/[A-Za-z0-9._\-/]+$#', $path) === 1 + && in_array(strtolower(pathinfo($path, PATHINFO_EXTENSION)), self::EXTENSIONS, true); + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index d2cb6b3..8403dd0 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -7,6 +7,7 @@ use App\Domain\Cms\NavigationItemPolicy; use App\Domain\Cms\Page; use App\Domain\Cms\PagePolicy; +use App\Domain\Cms\Widgets\Support\WebsiteImage; use App\Domain\Cms\Widgets\WidgetRegistry; use App\Domain\Media\FfmpegFilmTranscoder; use App\Domain\Media\FilmTranscoder; @@ -26,6 +27,7 @@ public function register(): void $this->app->bind(FilmTranscoder::class, FfmpegFilmTranscoder::class); // Je Anfrage einmal den Index der öffentlich genannten Medien bilden, nicht je Karte. $this->app->scoped(PublicMaterialReader::class); + $this->app->scoped(WebsiteImage::class); $this->app->singleton(WidgetRegistry::class, fn ($app): WidgetRegistry => new WidgetRegistry( array_map(fn (string $class) => $app->make($class), config('cms.widgets', [])), )); diff --git a/database/migrations/2026_11_19_090000_create_website_media_aliases.php b/database/migrations/2026_11_19_090000_create_website_media_aliases.php new file mode 100644 index 0000000..6e1269b --- /dev/null +++ b/database/migrations/2026_11_19_090000_create_website_media_aliases.php @@ -0,0 +1,28 @@ +id(); + $table->string('legacy_path')->unique(); + $table->foreignId('content_element_id')->constrained()->restrictOnDelete(); + $table->string('sha256', 64)->index(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('website_media_aliases'); + } +}; diff --git a/database/migrations/2026_11_19_090100_import_cms_images_into_media_manager.php b/database/migrations/2026_11_19_090100_import_cms_images_into_media_manager.php new file mode 100644 index 0000000..c8ce0d3 --- /dev/null +++ b/database/migrations/2026_11_19_090100_import_cms_images_into_media_manager.php @@ -0,0 +1,27 @@ +runningUnitTests()) { + return; + } + + ImportCmsImages::dispatch(); + } + + public function down(): void + { + // Nichts zurückzunehmen: Die übernommenen Medien und Zuordnungen bleiben; die Tabelle entfernt die vorige Migration. + } +}; diff --git a/docs/architektur/12_Entscheidungsprotokoll_ADR.md b/docs/architektur/12_Entscheidungsprotokoll_ADR.md index ff07a09..808f168 100644 --- a/docs/architektur/12_Entscheidungsprotokoll_ADR.md +++ b/docs/architektur/12_Entscheidungsprotokoll_ADR.md @@ -60,6 +60,7 @@ ## Übersicht der Architekturentscheidungen | ADR-37 | n8n-Anbindung | Option / nicht beschlossen | n8n allenfalls für externe Kanäle, ohne direkten Datenbankzugang | | ADR-38 | Layoutvertrag der Widgets | Umgesetzt auf Test (18.11.2026); UX-Abnahme offen | Zulässige Rasterbreiten, Höhen und Verhalten bei wenig Platz je Widget-Art in der bestehenden Registry; Darstellung nach realer Containerbreite | | ADR-39 | Premium-Karten mit Fachbezug | Umgesetzt auf Test (18.11.2026); gestalterische Freigabe v1.7 offen | Eine Karte je Platz im Abschnittsraster; Inhalte und Linkziel aus Thema, Medium oder Programm/Modul; keine Preise, keine Freigabe geschützter Medien | +| ADR-40 | Zentrale Medienverwaltung im CMS | Umgesetzt auf Test (19.11.2026); Abnahme offen | CMS-Bilder sind Medien des Medienmanagers (Kennung statt Pfad), öffentlich nur mit Website-Freigabe; frühere CMS-Bilder übernommen | --- @@ -516,3 +517,12 @@ ## ADR-39 – Premium-Karten mit Fachbezug **Offene Entscheidungen.** (1) Freigabe von Vorschaubildern für die Website und öffentliche Filmvorschauen (minimaler Erweiterungsbedarf in `cms-widget-registry.md` §13). (2) Ob bei Traineranleitungen schon der Titel auf der Programmseite öffentlich sein soll (Programmseite, nicht Karte). **Folgen und offene Prüfung.** Keine Migration; bestehende Seiten und Widgets unverändert (gemessen). Mit ADR-29 ersetzen öffentliche Profile die Übergangsregeln in `PublicCatalogReader` und `PublicMaterialReader`; die gespeicherten Karten ändern sich dadurch nicht. Offen: gestalterische Freigabe v1.7, freigegebene Motive statt Platzhaltern, eine kaufbare Angebotskarte (eigenes Fachobjekt „Angebot“ mit Umfang, Zweck und Lizenzbedingungen, nicht Teil dieser Karten). **Quelle.** Brand-UI-Kit v1.7 (`docs/Brand-UI-Kit/13_premium_karten_v1.7_entwurf`, README, `docs/design-config.json`); `docs/architektur/cms-widget-registry.md` §§4, 6, 11, 13; ADR-29, ADR-30, ADR-38. + +## ADR-40 – Zentrale Medienverwaltung im CMS + +**Status am 19.11.2026:** Umgesetzt auf `develop`/Testinstanz (Branch `feature/cms-medienverwaltung`); Abnahme durch den Betreiber offen. Baut auf der Website-Freigabe des Medienmanagers auf (`medienzugriff-fuer-komponenten.md`). +**Kontext.** Das CMS hatte eine eigene Bildablage (`cms/`, `PublishPublicMedia`). Redakteure sollen Bilder im Medienmanager, im Modul-/Programmeditor und in CMS-Widgets aus demselben Bestand verwenden; öffentlich darf nur erscheinen, was für die Website freigegeben ist. +**Entscheidung.** Alle Bildstellen (Einstieg, Bild und Text, redaktionelle Karten, Premium-Karten, Abschnittshintergrund) speichern die Kennung des Inhaltselements im bisherigen Bildschlüssel `image` und lesen über `WebsiteMedia`. Uploads im Widget-Dialog laufen über `WebsiteIntake`. Frühere CMS-Bilder werden per Warteschlangen-Job übernommen (dedupliziert, nichts gelöscht) und über `website_media_aliases` zugeordnet; die Zuordnung wird erst nach der ersten Website-Freigabe wirksam. Ein nicht freigegebenes Bild entfällt öffentlich, das Widget bleibt. +**Alternativen.** Schlüssel `refs.element` wie im Dokument (verworfen: kollidiert mit dem Fachobjekt der Medienkarte); Revisionen per Migration umschreiben (verworfen: Revisionen bleiben unverändert, Rollback); ganzes Widget bei fehlender Freigabe ausblenden (verworfen bis zur Entscheidung: entfernt Überschriften und H1). +**Folgen und offene Prüfung.** Rollback zeigt nach der Umstellung gespeicherte Bilder nicht (Registry §9). Website-Bilder werden bis 2400 px abgeleitet. Offen: Entscheidung „Bild entfällt“ vs. „Widget entfällt“; übernommene Medien tragen Dateinamen als Titel und keine Quellenzeile; ein unter `cms/` liegendes Originalmotiv (`lara-felix-park-original`) wurde mit übernommen und ist damit ein freigegebenes Medium – prüfen und gegebenenfalls zurücknehmen. +**Quelle.** `docs/architektur/medienzugriff-fuer-komponenten.md`; `cms-widget-registry.md` §§7, 9; ADR-30, ADR-38, ADR-39. diff --git a/docs/architektur/cms-widget-registry.md b/docs/architektur/cms-widget-registry.md index 46954cc..62d0ac6 100644 --- a/docs/architektur/cms-widget-registry.md +++ b/docs/architektur/cms-widget-registry.md @@ -140,9 +140,12 @@ ## 6. Öffentliche Freigabe von Programmen und Modulen (Übergangsregel) ## 7. Medien -- Wählbar sind nur Bilder im öffentlichen Website-Bereich `cms/` (`media_public` bzw. noch nicht übertragene Uploads in `cms_incoming`). Bibliotheksmedien und Filmstandbilder erscheinen nicht, auch nicht als Abschnittshintergrund. -- Neue Uploads (Widgets und Abschnittshintergründe) landen im Webprozess in `cms_incoming` (privater Speicher); `PublishPublicMedia` überträgt sie in der Hintergrundverarbeitung nach `media_public`. Der Web-Prozess schreibt nicht in den Medienbestand. -- Widget-Bilder sind an einen Alternativtext gebunden (Ausnahme: Kartenbilder gelten als dekorativ, `alt=""`). Abschnittshintergründe sind dekorativ (`alt=""`); tragende Aussagen stehen als HTML-Text in den Widgets. +Alle Bilder kommen aus dem zentralen Medienmanager (`docs/architektur/medienzugriff-fuer-komponenten.md`, Abschnitt +„Umsetzung im CMS“). Gespeichert wird die Kennung des Mediums in `refs.image`, `data.items[].image` bzw. +`style.image`; öffentlich erscheint ein Bild nur mit Website-Freigabe (`WebsiteMedia`, Route `website.media`). +Gemeinsame Felder: `ImageRefFields` (Auswahl mit Vorschaubild und Status, Upload über `WebsiteIntake`, Anzeige des +gewählten Mediums). Frühere Pfade unter `cms/` gelten über `WebsiteMediaAlias` als das übernommene Medium, ohne +Zuordnung weiter als öffentliches CMS-Bild. Bibliotheksmedien ohne Website-Freigabe erscheinen öffentlich nie. ## 8. Editor und Vorschau @@ -164,6 +167,11 @@ ## 8. Editor und Vorschau ## 9. Rollback und Datenformat (wichtig vor dem Merge nach `main`) +**Medien aus dem Medienmanager (ADR-40).** Revisionen, die nach der Umstellung gespeichert werden, enthalten im +Bildschlüssel eine Kennung (Zahl) statt eines Pfads. Ein Code-Rollback auf eine Fassung davor zeigt diese Bilder nicht +(die ältere Fassung kennt nur `cms/`-Pfade); Texte und Gestaltung bleiben. Die Dateien unter `cms/` und frühere +Revisionen bleiben unverändert, die Zuordnungstabelle `website_media_aliases` ist additiv. + **Speicherung.** Jede neue Revision schreibt zwei Spalten: | Spalte | Inhalt | Wer liest sie | diff --git a/docs/architektur/medienzugriff-fuer-komponenten.md b/docs/architektur/medienzugriff-fuer-komponenten.md index 463e8bb..12b6692 100644 --- a/docs/architektur/medienzugriff-fuer-komponenten.md +++ b/docs/architektur/medienzugriff-fuer-komponenten.md @@ -88,3 +88,44 @@ ## Was eine Komponente einhält 5. Der Web-Prozess schreibt nicht nach `originals/` und nicht nach `derived/` oder `public/`. Eine Karte oder eine Komponente begründet keine Berechtigung. + +## Umsetzung im CMS (19.11.2026, ADR-40) + +Alle Bildstellen des CMS lesen den zentralen Medienbestand: Einstieg (Hero), Bild und Text, redaktionelle Karten, +Premium-Karten (Kartenbild) und Abschnittshintergrund. Das CMS hat keine eigene Medienverwaltung mehr. + +- **Gespeichert** wird die Kennung des Inhaltselements im jeweiligen Bildschlüssel: `refs.image` (Einstieg, Bild und + Text, Premium-Karten), `data.items[].image` (redaktionelle Karten), `style.image` (Abschnittshintergrund). + **Abweichung von `refs.element`:** Die Medienkarte verwendet `refs.element` bereits für ihr Fachobjekt; ein + gemeinsamer Bildschlüssel `image` hält alle Widgets gleich und ändert die gespeicherte Struktur nicht. +- **Lesen:** `App\Domain\Cms\Widgets\Support\WebsiteImage` ruft `WebsiteMedia::present` auf. Öffentlich erscheint + ein Bild nur über `website.media`. In der Redaktionsvorschau erscheint ein nicht freigegebenes Bild als + Vorschaubild über `editorial.card` mit Hinweis; öffentlich nie. +- **Nicht freigegeben:** Es entfällt nur das Bild; das Widget erscheint mit seiner Darstellung ohne Bild (Überschrift, + Text, Schaltflächen bleiben). Das ist eine bewusste Auslegung von „gibt das Widget nichts aus“, damit eine + zurückgenommene Freigabe keine Überschrift (auch keine H1) von einer Seite entfernt. Entscheidung offen für Lars. +- **Neu hochladen im Widget-Dialog:** Die Datei geht über `WebsiteIntake::acceptImage` sofort in den Medienmanager + und wird ausgewählt. Titel aus dem Dateinamen, ohne Quellenzeile; beides ist im Medienmanager änderbar. Die + Warteschlange leitet ab und gibt frei (wie dokumentiert). +- **Auswahl:** alle Bilder (`output_class = bild`, nicht archiviert, keine Traineranleitung) mit Vorschaubild, Titel + und Website-Status; das gewählte Medium mit Status und Verweis auf den Medienmanager. Die Bildauswahl des + Modul-/Programmeditors ist an dessen Livewire-Seite gebunden und lässt sich nicht als Formularfeld einhängen; das + Bedienmuster (Suche, Vorschaubild, Auswahl) ist übernommen. +- **Alternativtext:** aus dem Medium (`website_alt`, sonst Titel). Das Feld im Widget ist eine optionale Abweichung. +- **Website-Ableitung:** Bilder werden bis 2400 px breit abgeleitet (vorher 640 px), nie vergrößert. +- **Medienmanager:** Die Medienansicht nennt die Website-Seiten, auf denen ein Bild verwendet wird + (`WebsiteImageUsage`), damit vor dem Zurücknehmen sichtbar ist, welche Seiten das Bild verlieren. + +### Übernahme der früheren CMS-Bilder + +- Der Job `ImportCmsImages` (angestoßen von einer Migration, ausgeführt von der Warteschlange) nimmt jede Bilddatei + unter `media_public/cms/` über `WebsiteIntake` auf. Bytegleiche Dateien werden ein Medium (SHA-256). Der Titel + kommt aus dem Dateinamen ohne Zufallskennung. Nichts wird gelöscht; der Job ist wiederholbar. +- `website_media_aliases` ordnet jeden früheren Pfad seinem Medium zu. **Wirksam** wird die Zuordnung erst, wenn das + Medium einmal für die Website freigegeben war; bis dahin (oder wenn die Ableitung scheitert) gilt der frühere Pfad + weiter, damit keine Seite ihr Bild verliert. +- Danach entscheidet die Website-Freigabe des Mediums allein, auch über die frühere Adresse `/medien/cms/…` + (404, wenn zurückgenommen). +- Gespeicherte Revisionen bleiben unverändert; frühere Pfade werden beim Darstellen zugeordnet und beim nächsten + Speichern durch die Kennung ersetzt. Frühere Pfade ohne Zuordnung bleiben über `PublicMedia` gültig. +- Eine Slideshow gibt es im CMS nicht; `WebsiteMedia::presentMany` ist für sie vorbereitet und noch unbenutzt. diff --git a/resources/views/filament/cms/styles.blade.php b/resources/views/filament/cms/styles.blade.php index ac8d14d..df07e1a 100644 --- a/resources/views/filament/cms/styles.blade.php +++ b/resources/views/filament/cms/styles.blade.php @@ -54,6 +54,23 @@ .luf-sections .fi-fo-repeater-item-header .fi-icon-btn, .luf-sections .fi-fo-builder-item-header .fi-icon-btn { min-width: 2.25rem; min-height: 2.25rem; opacity: 1; } .luf-sections .fi-fo-builder-item-header { flex-wrap: wrap; } + /* Medienpicker (Bilder aus dem Medienmanager): Vorschaubild, Titel und Website-Status in der Auswahl. */ + .luf-media-option { display: flex; align-items: center; gap: .75rem; min-width: 0; } + .luf-media-option img, .luf-media-option-empty { flex: none; width: 4.5rem; height: 2.75rem; object-fit: cover; border-radius: .375rem; background: #eef1ee; } + .luf-media-option-text { display: flex; flex-direction: column; gap: .15rem; min-width: 0; } + .luf-media-option-text strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } + .luf-media-badge { align-self: flex-start; padding: 0 .45rem; border-radius: 999px; font-size: .72rem; line-height: 1.35rem; } + .luf-media-badge-ok { background: #e3f0d8; color: #2d5c07; } + .luf-media-badge-warn { background: #fff1c7; color: #6b4b00; } + .luf-media-badge-wait { background: #e5eef8; color: #18456f; } + .luf-media-badge-quiet { background: #eceff1; color: #3e4c5c; } + .luf-media-status { display: flex; gap: 1rem; align-items: flex-start; padding: .75rem; border: 1px solid #d5ddd6; border-radius: .5rem; } + .luf-media-status img { width: 10rem; height: auto; border-radius: .375rem; } + .luf-media-status strong { display: block; } + .luf-media-status p { margin: .25rem 0 .4rem; font-size: .875rem; } + .luf-media-status a { font-size: .875rem; text-decoration: underline; } + .luf-media-status-unreleased, .luf-media-status-missing { border-color: #e7c35a; background: #fffaeb; } + .luf-media-status-pending { border-color: #9cbbe0; background: #f3f8fd; }