label('Ansehen') ->url(function (): ?string { $version = $this->latestVersion(); return $version === null ? null : route('content.preview', $version); }) ->visible(fn (): bool => $this->latestVersion() !== null) ->openUrlInNewTab(), Action::make('version') ->label('Fassung veröffentlichen') ->schema([ Textarea::make('body')->label('Text'), FileUpload::make('incoming') ->label('Datei') ->disk('cms_incoming') ->directory('inhalte') ->helperText('Film, Audio oder PDF. Die Datei wird übernommen und ist danach unter Ansehen sichtbar.'), TextInput::make('decision_seconds') ->label('Entscheidungsmarke in Sekunden') ->numeric() ->minValue(0) ->helperText('Nur für Filme: der Kursplayer pausiert an dieser Stelle.'), TextInput::make('change_note')->label('Änderungsnotiz'), ]) ->action(function (array $data): void { $this->report(function () use ($data): void { /** @var ContentElement $element */ $element = $this->getRecord(); $metadata = []; $incoming = $data['incoming'] ?? null; if (is_array($incoming)) { $incoming = array_values(array_filter($incoming, 'is_string'))[0] ?? null; } if (is_string($incoming) && $incoming !== '') { $metadata['incoming'] = $incoming; } if (is_numeric($data['decision_seconds'] ?? null)) { $metadata['decision_seconds'] = (int) $data['decision_seconds']; } app(ContentService::class)->publishElementVersion( $element, $data['body'] ?? null, $metadata, $data['change_note'] ?? null, ); }, 'Die Fassung ist gespeichert.'); $this->getRecord()->unsetRelations(); $this->getRecord()->refresh(); }), ]; } private function latestVersion(): ?ContentElementVersion { /** @var ContentElement $element */ $element = $this->getRecord(); return $element->versions()->orderByDesc('number')->first(); } }