- Wird eine schon übernommene Stelle erneut gewählt, nennt die Meldung den tatsächlichen Stand: bereits freigegeben, wird verarbeitet oder Website-Freigabe zurückgenommen (bleibt zurückgenommen). Ein bei der Verarbeitung gescheitertes oder archiviertes Bild wird nicht wiederverwendet; die Herkunft zeigt dann auf das neue Bild. - „Medium löschen“ erreicht jetzt Standbilder (film_still_sources: cascade) und übernommene CMS-Bilder (website_media_aliases: Zuordnung bleibt als Sperre, die frühere Adresse /medien/cms/… liefert 404, das Widget zeigt kein Bild). Vorher hätte der Fremdschlüssel das Löschen mit einem Fehler abgebrochen. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
213 lines
7.2 KiB
PHP
213 lines
7.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Support;
|
|
|
|
use App\Domain\Catalog\ContentElement;
|
|
use App\Domain\Catalog\DomainRuleException;
|
|
use App\Domain\Cms\Widgets\Support\WebsiteImage;
|
|
use App\Domain\Media\FilmStill;
|
|
use App\Domain\Media\WebsiteMedia;
|
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
|
use Filament\Notifications\Notification;
|
|
|
|
/**
|
|
* Bildauswahl im CMS über den gemeinsamen visuellen Picker (Dokument 14 §9) statt einer eigenen Auswahlliste.
|
|
* Ein Bildfeld (filament.cms.bild-feld) öffnet den Picker mit seinem Formularpfad; „Bild übernehmen“ schreibt die
|
|
* Kennung des Mediums in genau dieses Feld, auch im geöffneten Bausteindialog. Gespeichert wird weiterhin nur mit dem
|
|
* Seitenentwurf. Die Auswahl gibt kein Bild für die Website frei.
|
|
*/
|
|
trait ChoosesWebsiteImages
|
|
{
|
|
use ChoosesMedia;
|
|
|
|
/** Formularpfad des Bildfelds, in das die Auswahl übernommen wird. */
|
|
public ?string $bildZiel = null;
|
|
|
|
public function openWebsiteImagePicker(string $pfad): void
|
|
{
|
|
if (preg_match('/^(data|mountedActions\.\d+\.data)(\.[A-Za-z0-9_-]+)+$/', $pfad) !== 1) {
|
|
return;
|
|
}
|
|
|
|
$this->resetPicker('website-bild');
|
|
$this->pickerKind = 'bild';
|
|
$this->bildZiel = $pfad;
|
|
$this->forceRenderForPicker();
|
|
}
|
|
|
|
/**
|
|
* Medien- und Materialkarte: das Vorschaubild des Films als Bild für die Website übernehmen. Es entsteht ein Bild
|
|
* im Medienmanager (einmal gespeichert), das im Bildfeld ausgewählt wird. Die Datei des Films bleibt geschützt.
|
|
*/
|
|
public function adoptFilmThumbnail(string $pfad, int $elementId): void
|
|
{
|
|
$this->adoptFilmStill($pfad, $elementId, fn (FilmStill $stills, ContentElement $film): ContentElement => $stills->fromThumbnail($film, auth('staff')->user()));
|
|
}
|
|
|
|
/**
|
|
* Medien- und Materialkarte: eine Stelle des Films wählen und als Bild für die Website übernehmen.
|
|
*/
|
|
public function adoptFilmFrame(string $pfad, int $elementId, string $sekunde): void
|
|
{
|
|
if (! is_numeric($sekunde)) {
|
|
Notification::make()->danger()->title('Bitte eine Zeitposition in Sekunden angeben.')->send();
|
|
|
|
return;
|
|
}
|
|
|
|
$this->adoptFilmStill($pfad, $elementId, fn (FilmStill $stills, ContentElement $film): ContentElement => $stills->fromSecond($film, (float) $sekunde, auth('staff')->user()));
|
|
}
|
|
|
|
/**
|
|
* @param callable(FilmStill, ContentElement): ContentElement $make
|
|
*/
|
|
private function adoptFilmStill(string $pfad, int $elementId, callable $make): void
|
|
{
|
|
abort_unless(ContentElementResource::editor(), 403);
|
|
|
|
if (preg_match('/^(data|mountedActions\.\d+\.data)(\.[A-Za-z0-9_-]+)+\.image$/', $pfad) !== 1) {
|
|
return;
|
|
}
|
|
|
|
$film = ContentElement::query()->with('editorialContentKind')->find($elementId);
|
|
|
|
if (! $film instanceof ContentElement) {
|
|
return;
|
|
}
|
|
|
|
$stills = app(FilmStill::class);
|
|
|
|
try {
|
|
$still = $make($stills, $film);
|
|
} catch (DomainRuleException $exception) {
|
|
Notification::make()->danger()->title($exception->getMessage())->send();
|
|
|
|
return;
|
|
}
|
|
|
|
data_set($this, $pfad, $still->id);
|
|
$title = ($still->display_title ?: $still->working_title);
|
|
|
|
if (! $stills->reused) {
|
|
Notification::make()
|
|
->success()
|
|
->title('Im Medienmanager angelegt: „'.$title.'“')
|
|
->body('Das Bild ist als Kartenbild ausgewählt. Nach der Verarbeitung wird es für die Website freigegeben; dort lässt sich die Freigabe auch zurücknehmen.')
|
|
->send();
|
|
|
|
return;
|
|
}
|
|
|
|
// Dieselbe Stelle war schon übernommen: Der tatsächliche Stand des Bildes entscheidet über die Meldung.
|
|
if (app(WebsiteMedia::class)->present($still) !== null) {
|
|
Notification::make()->success()->title('Bereits im Medienmanager: „'.$title.'“')->body('Diese Stelle war schon übernommen. Das Bild ist als Kartenbild ausgewählt.')->send();
|
|
} elseif (blank($still->thumbnail_path) && blank($still->thumbnail_error)) {
|
|
Notification::make()->success()->title('Bereits im Medienmanager: „'.$title.'“')->body('Das Bild wird noch verarbeitet und danach für die Website freigegeben.')->send();
|
|
} else {
|
|
Notification::make()->warning()->title('Bild ausgewählt, aber nicht für die Website freigegeben: „'.$title.'“')
|
|
->body('Diese Stelle war schon übernommen und die Website-Freigabe wurde zurückgenommen. Das Bild erscheint öffentlich erst wieder, wenn sie im Medienmanager (Reiter „Website“) erneut gegeben wird.')
|
|
->persistent()
|
|
->send();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Filament rendert bei offenen Aktionsdialogen nur den Dialogteil neu; der Picker liegt darüber und braucht die
|
|
* ganze Seite.
|
|
*/
|
|
public function hydrateChoosesWebsiteImages(): void
|
|
{
|
|
if ($this->pickerOpen) {
|
|
$this->forceRenderForPicker();
|
|
}
|
|
}
|
|
|
|
public function pickerAllowsMany(): bool
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function closePicker(): void
|
|
{
|
|
$this->pickerOpen = false;
|
|
$this->pickerSelected = '';
|
|
$this->pickerInspected = '';
|
|
$this->pickerMarked = [];
|
|
$this->bildZiel = null;
|
|
$this->forceRenderForPicker();
|
|
}
|
|
|
|
public function confirmPicker(): void
|
|
{
|
|
$target = array_key_first($this->pickerMarked);
|
|
$ziel = $this->bildZiel;
|
|
|
|
if ($target === null || $ziel === null) {
|
|
return;
|
|
}
|
|
|
|
$row = app(EditorialCatalog::class)->rowForTarget((string) $target, 0, allowDraft: true);
|
|
$element = isset($row['element_id']) ? ContentElement::query()->find((int) $row['element_id']) : null;
|
|
|
|
if (! $element instanceof ContentElement || ! WebsiteImage::isSelectable($element)) {
|
|
Notification::make()->danger()->title('Dieses Medium kann nicht als Website-Bild gewählt werden.')->send();
|
|
|
|
return;
|
|
}
|
|
|
|
data_set($this, $ziel, $element->id);
|
|
$this->closePicker();
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function pickerKinds(): array
|
|
{
|
|
return ['bild' => 'Bilder'];
|
|
}
|
|
|
|
public function pickerTitle(): string
|
|
{
|
|
return 'Bild aus dem Medienmanager';
|
|
}
|
|
|
|
public function pickerConfirmLabel(): string
|
|
{
|
|
return 'Bild übernehmen';
|
|
}
|
|
|
|
/**
|
|
* @return array{art: string, titel: string}
|
|
*/
|
|
public function pickerKontext(): array
|
|
{
|
|
$pfad = property_exists($this, 'record') && is_object($this->record ?? null) ? (string) ($this->record->path ?? '') : '';
|
|
|
|
return ['art' => 'die Seite', 'titel' => $pfad !== '' ? $pfad : 'neue Seite'];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function presentationRoleOptions(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>|null
|
|
*/
|
|
public function pickerReplacing(): ?array
|
|
{
|
|
return null;
|
|
}
|
|
|
|
private function forceRenderForPicker(): void
|
|
{
|
|
if (method_exists($this, 'forceRender')) {
|
|
$this->forceRender();
|
|
}
|
|
}
|
|
}
|