resetPicker('website-bild'); $this->pickerKind = 'bild'; $this->bildZiel = $pfad; $this->forceRenderForPicker(); } /** * Bild und Text: ein Film aus dem Medienmanager als Video wählen. Gleicher Wähler wie beim Bild, nur mit Filmen; das * Ziel ist ausschließlich ein Videofeld (…video). Die Auswahl gibt nichts frei. */ public function openWebsiteVideoPicker(string $pfad): void { if (preg_match('/^(data|mountedActions\.\d+\.data)(\.[A-Za-z0-9_-]+)+\.video$/', $pfad) !== 1) { return; } $this->resetPicker('website-video'); $this->pickerKind = 'film'; $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())); } /** * Programm- und Modulkarte: das Vorschaubild des Programms oder Moduls als Bild für die Website übernehmen * (Bild-Medium im Medienmanager, einmal kopiert). */ public function adoptCompositionThumbnail(string $pfad, int $compositionId): void { abort_unless(ContentElementResource::editor(), 403); if ($this->imageTargetIsInvalid($pfad)) { return; } $composition = Composition::query()->find($compositionId); if (! $composition instanceof Composition) { return; } $stills = app(CompositionStill::class); try { $still = $stills->fromThumbnail($composition, auth('staff')->user()); } catch (DomainRuleException $exception) { Notification::make()->danger()->title($exception->getMessage())->send(); return; } data_set($this, $pfad, $still->id); $this->announceAdoptedStill($still, $stills->reused, 'Dieses Vorschaubild war schon übernommen.'); } /** * @param callable(FilmStill, ContentElement): ContentElement $make */ private function adoptFilmStill(string $pfad, int $elementId, callable $make): void { abort_unless(ContentElementResource::editor(), 403); if ($this->imageTargetIsInvalid($pfad)) { 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); $this->announceAdoptedStill($still, $stills->reused, 'Diese Stelle war schon übernommen.'); } /** Nur das Bildfeld eines Widgets oder Abschnitts ist ein zulässiges Ziel (…image). */ private function imageTargetIsInvalid(string $pfad): bool { return preg_match('/^(data|mountedActions\.\d+\.data)(\.[A-Za-z0-9_-]+)+\.image$/', $pfad) !== 1; } /** * Meldung nach dem tatsächlichen Stand des Bildes: neu angelegt, schon vorhanden und freigegeben, wird verarbeitet * oder Website-Freigabe zurückgenommen (bleibt zurückgenommen). */ private function announceAdoptedStill(ContentElement $still, bool $reused, string $reusedText): void { $title = ($still->display_title ?: $still->working_title); if (! $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; } if (app(WebsiteMedia::class)->present($still) !== null) { Notification::make()->success()->title('Bereits im Medienmanager: „'.$title.'“')->body($reusedText.' 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($reusedText.' 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; $video = $this->pickerPurpose === 'website-video'; if ($video ? ! ($element instanceof ContentElement && app(HeroVideo::class)->isSelectable($element)) : ! ($element instanceof ContentElement && WebsiteImage::isSelectable($element))) { Notification::make()->danger()->title($video ? 'Dieser Film kann nicht als Video gewählt werden.' : 'Dieses Medium kann nicht als Website-Bild gewählt werden.')->send(); return; } data_set($this, $ziel, $element->id); $this->closePicker(); } /** * @return array */ public function pickerKinds(): array { return $this->pickerPurpose === 'website-video' ? ['film' => 'Filme'] : ['bild' => 'Bilder']; } public function pickerTitle(): string { return $this->pickerPurpose === 'website-video' ? 'Video aus dem Medienmanager' : 'Bild aus dem Medienmanager'; } public function pickerConfirmLabel(): string { return $this->pickerPurpose === 'website-video' ? 'Video übernehmen' : '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 */ public function presentationRoleOptions(): array { return []; } /** * @return array|null */ public function pickerReplacing(): ?array { return null; } private function forceRenderForPicker(): void { if (method_exists($this, 'forceRender')) { $this->forceRender(); } } }