Pflege Anzeigedaten ohne neue Fassung und zeige sie in den echten Karten.
Deploy Test / test (push) Successful in 47s
Deploy Test / deploy (push) Successful in 28s

Der Medieneditor trennt Beschreibung, Inhalt, Fassungen und Verwendung. Der vorhandene Picker filtert nach Zusammenhang und lässt Entwürfe für die gemeinsame Freigabe sichtbar.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-18 20:03:56 +01:00
1 parent 3e56314cf9
commit d37a7093dd
13 files changed
+827 -54

No files matched your search

@@ -6,20 +6,25 @@
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\ContentVersionStatus;
use App\Domain\Catalog\EditorialDimensionValue;
use App\Domain\Catalog\IdentityChange;
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\IdentityDimensionValue;
use App\Domain\Catalog\IdentityProfile;
use App\Domain\Catalog\Pillar;
use App\Domain\Catalog\PillarService;
use App\Domain\Cms\Catalog\PublicMaterialReader;
use App\Domain\Cms\Widgets\RenderContext;
use App\Domain\Media\ThumbnailRef;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Support\CatalogReading;
use App\Filament\Support\EditorialCatalog;
use App\Filament\Support\ElementRevision;
use App\Filament\Support\MediaLibrary;
use App\Filament\Support\ReportsDomainRules;
use App\Http\Controllers\ContentPreviewController;
use App\Jobs\DeriveThumbnail;
use Filament\Actions\Action;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\ViewRecord;
use Filament\Schemas\Components\View;
use Filament\Schemas\Schema;
@@ -47,6 +52,42 @@ class ViewContentElement extends ViewRecord
public mixed $previewUpload = null;
public string $bereich = 'inhalt';
public string $workingTitle = '';
public string $displayTitle = '';
public string $summary = '';
public string $descriptionText = '';
public string $usageNote = '';
public string $licenseNote = '';
public int|string|null $kindId = null;
/** @var list<int|string> */
public array $pillarIds = [];
/** @var list<int|string> */
public array $dimensionIds = [];
public string $editorialFeedback = '';
public string $previewWidth = '640';
public string $previewSurface = 'website';
public string $pickerQuery = '';
public string $pickerContext = 'modul';
public string $pickerLayout = 'kacheln';
public string $pickerSelected = '';
public function mount(int|string $record): void
{
parent::mount($record);
@@ -57,13 +98,18 @@ public function mount(int|string $record): void
$this->fassung = $requested;
}
$bereich = (string) request()->query('bereich', 'inhalt');
$this->bereich = in_array($bereich, ['beschreibung', 'inhalt', 'fassungen', 'herkunft', 'verwendung', 'auswahl', 'vorschau'], true)
? $bereich
: 'inhalt';
$this->thumbnailAlt = (string) ($this->getRecord()->thumbnail_alt ?? '');
$this->fillEditorial();
$this->syncBodyDraft();
}
public function getSubheading(): string|Htmlable|null
{
return 'Jede Fassung hat eine eigene Nummer und bleibt einsehbar. Beschreibung, Arbeitstitel und Säulen gehören zum Medium und ändern keine Fassung. Eine deaktivierte Fassung wird nicht mehr ausgeliefert und lässt sich nicht neu einbauen.';
return 'Beschreibung, Anzeigename, Kurzbeschreibung und Vorschaubild gehören zum Medium und ändern keine Fassung. Eine neue Film- oder Textdatei entsteht nur über eine neue Fassung. Die Website zeigt nur, was dafür freigegeben ist.';
}
public function infolist(Schema $schema): Schema
@@ -242,40 +288,6 @@ public function deactivateAction(): Action
protected function getHeaderActions(): array
{
return [
Action::make('describe')
->label('Beschreibung ändern')
->visible(fn (): bool => ContentElementResource::editor())
->fillForm(fn (): array => [
'working_title' => $this->getRecord()->working_title,
'description' => $this->getRecord()->description,
'usage_note' => $this->getRecord()->usage_note,
'license_note' => $this->getRecord()->license_note,
'pillars' => $this->getRecord()->pillars()->pluck('pillars.id')->all(),
])
->schema([
TextInput::make('working_title')->label('Arbeitstitel')->required(),
Textarea::make('description')->label('Beschreibung')->rows(4)
->helperText('Gilt für das Medium. Speichern legt keine neue Fassung an.'),
Textarea::make('usage_note')->label('Hinweise für den Einsatz')->rows(4),
Textarea::make('license_note')->label('Interner Lizenzvermerk')->rows(3)
->helperText('Nur in der Verwaltung. Nicht in der Bibliothek und nicht auf der Website.'),
CheckboxList::make('pillars')
->label('Fachliche Säulen')
->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all()),
])
->action(function (array $data): void {
$this->report(function () use ($data): void {
/** @var ContentElement $element */
$element = $this->getRecord();
app(ContentService::class)->describe($element, (string) $data['working_title'], $data['description'] ?? null);
app(IdentityProfile::class)->fill($element, [
'usage_note' => $data['usage_note'] ?? null,
'license_note' => $data['license_note'] ?? null,
], auth()->user());
app(PillarService::class)->assign($element, array_map(intval(...), $data['pillars'] ?? []));
}, 'Die Beschreibung ist gespeichert.');
$this->getRecord()->refresh();
}),
Action::make('releaseVersion')
->label('Fassung freigeben')
->modalHeading('Fassung freigeben')
@@ -395,6 +407,7 @@ private function pictureCaption(ContentElement $element): string
return match ($source) {
'eigen' => 'Eigenes Vorschaubild.',
'datei' => 'Vorschaubild aus der Datei des Mediums.',
'bestand' => 'Vorschaubild aus einem Bild im Bestand. Es ist damit nicht für die Website freigegeben.',
default => '',
};
}
@@ -406,4 +419,234 @@ private function ownedVersion(int $id): ?ContentElementVersion
return $element->versions()->whereKey($id)->first();
}
public function saveEditorial(): void
{
abort_unless(ContentElementResource::editor(), 403);
/** @var ContentElement $element */
$element = $this->getRecord();
$title = trim($this->workingTitle);
if ($title === '') {
$this->editorialFeedback = 'Der Arbeitstitel fehlt.';
return;
}
$versions = $element->versions()->count();
app(IdentityProfile::class)->fill($element, [
'working_title' => $title,
'display_title' => $this->displayTitle,
'summary' => $this->summary,
'description' => $this->descriptionText,
'usage_note' => $this->usageNote,
'license_note' => $this->licenseNote,
'thumbnail_alt' => $this->thumbnailAlt,
'editorial_content_kind_id' => filled($this->kindId) ? (int) $this->kindId : null,
], auth()->user());
app(PillarService::class)->assign($element, array_map(intval(...), $this->pillarIds));
$ids = array_map(intval(...), $this->dimensionIds);
IdentityDimensionValue::query()
->where('subject_type', $element->getMorphClass())
->where('subject_id', $element->id)
->where('origin', 'direkt')
->whereNotIn('editorial_dimension_value_id', $ids === [] ? [0] : $ids)
->delete();
foreach (EditorialDimensionValue::query()->whereIn('id', $ids)->get() as $value) {
app(IdentityDimension::class)->assign($element, $value, 'direkt');
}
$element->refresh();
$this->fillEditorial();
$this->editorialFeedback = $element->versions()->count() === $versions
? 'Gespeichert. Es gibt keine neue Fassung.'
: 'Gespeichert. Prüfe die Fassungen, ihre Zahl hat sich geändert.';
}
public function adoptLibraryImage(): void
{
abort_unless(ContentElementResource::editor(), 403);
/** @var ContentElement $element */
$element = $this->getRecord();
$detail = $this->selectionDetail();
$sourceId = (int) ($detail['element_id'] ?? 0);
$source = $sourceId > 0 ? ContentElement::query()->find($sourceId) : null;
$path = $source?->thumbnail_path;
if (! $source instanceof ContentElement || $source->output_class !== 'bild' || ! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) {
$this->pictureFeedback = 'Dieses Bild hat noch kein übernehmbares Vorschaubild.';
return;
}
$versions = $element->versions()->count();
app(IdentityProfile::class)->fill($element, [
'thumbnail_path' => $path,
'thumbnail_alt' => filled($source->thumbnail_alt) ? $source->thumbnail_alt : $source->working_title,
'thumbnail_source' => 'bestand',
'thumbnail_error' => null,
], auth()->user());
$element->refresh();
$this->thumbnailAlt = (string) ($element->thumbnail_alt ?? '');
$this->pictureFeedback = $element->versions()->count() === $versions
? 'Vorschaubild übernommen. Es gibt keine neue Fassung. Für die Website ist es damit nicht freigegeben.'
: 'Vorschaubild übernommen. Prüfe die Fassungen.';
}
/**
* @return array{items: list<array<string, mixed>>, more: bool}
*/
public function selection(): array
{
return app(EditorialCatalog::class)->browse(
$this->pickerQuery,
$this->pickerContext === 'bild' ? 'bild' : 'alle',
'',
0,
elementsOnly: $this->pickerContext !== 'modul',
);
}
/**
* @return array<string, mixed>|null
*/
public function selectionDetail(): ?array
{
if ($this->pickerSelected === '') {
return null;
}
$row = app(EditorialCatalog::class)->rowForTarget($this->pickerSelected, 0, allowDraft: true);
if ($row === null || ! isset($row['element_id'])) {
return $row;
}
$element = ContentElement::query()->with('editorialContentKind')->find((int) $row['element_id']);
if ($element instanceof ContentElement) {
$row['visibility'] = app(PublicMaterialReader::class)->visibilityNote($element);
}
return $row;
}
public function previewHtml(): string
{
/** @var ContentElement $element */
$element = $this->getRecord();
$draft = [
'working_title' => $this->workingTitle,
'display_title' => $this->displayTitle,
'summary' => $this->summary,
'thumbnail_alt' => $this->thumbnailAlt,
];
if ($this->previewSurface === 'bibliothek') {
$title = trim($this->displayTitle) !== '' ? trim($this->displayTitle) : trim($this->workingTitle);
return view('member.partials.card', [
'href' => '#vorschau',
'card' => [
'title' => $title !== '' ? $title : $element->working_title,
'summary' => trim($this->summary) !== '' ? trim($this->summary) : null,
'kind' => PublicMaterialReader::outputLabel((string) $element->output_class),
'coverage' => 'offen',
'image' => trim($this->thumbnailAlt) !== '' ? trim($this->thumbnailAlt) : $title,
'image_url' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path),
'error' => 'Vorschau der Kartenform. Ob jemand sie öffnen darf, entscheidet die Lizenz.',
],
])->render();
}
$subject = app(PublicMaterialReader::class)->subject($element->id, true, $draft);
if ($subject === null) {
return '<p class="preview-note">Für dieses Medium liegt noch keine anzeigbare Fassung vor. Die Karte erscheint deshalb auch in der Vorschau nicht.</p>';
}
return view('widgets.premium_card', [
'subject' => $subject,
'context' => RenderContext::preview(),
'cardStyle' => $subject->style ?? 'media',
'imageUrl' => null,
'alt' => '',
'focus' => ['x' => 50, 'y' => 45],
'format' => 'landscape',
'fit' => 'cover',
'headingTag' => 'h3',
'show' => ['summary' => true, 'kind' => true, 'meta' => true, 'action' => true],
'actionLabel' => 'Ansehen',
'note' => null,
'stacked' => $this->previewWidth === '390',
])->render();
}
/**
* @return list<array{field: string, after: string, when: string}>
*/
public function editorialHistory(): array
{
/** @var ContentElement $element */
$element = $this->getRecord();
$labels = [
'working_title' => 'Arbeitstitel',
'display_title' => 'Anzeigename',
'description' => 'Beschreibung',
'summary' => 'Kurzbeschreibung',
'usage_note' => 'Einsatzhinweis',
'license_note' => 'Interner Lizenzvermerk',
'thumbnail_alt' => 'Alternativtext',
'thumbnail_path' => 'Vorschaubild',
'thumbnail_source' => 'Herkunft des Vorschaubilds',
'editorial_content_kind_id' => 'Inhaltsart',
];
return IdentityChange::query()
->where('subject_type', $element->getMorphClass())
->where('subject_id', $element->id)
->latest('occurred_at')
->limit(8)
->get()
->map(fn (IdentityChange $change): array => [
'field' => $labels[$change->field] ?? $change->field,
'after' => is_scalar($change->after) ? (string) $change->after : '',
'when' => $change->occurred_at?->timezone(config('app.timezone'))->format('d.m.Y H:i') ?? '',
])
->all();
}
/**
* @return array<string, mixed>
*/
public function usageCard(): array
{
/** @var ContentElement $element */
$element = $this->getRecord();
return app(MediaLibrary::class)->cardFor($element, ContentElementResource::editor());
}
private function fillEditorial(): void
{
/** @var ContentElement $element */
$element = $this->getRecord();
$this->workingTitle = (string) $element->working_title;
$this->displayTitle = (string) ($element->display_title ?? '');
$this->summary = (string) ($element->summary ?? '');
$this->descriptionText = (string) ($element->description ?? '');
$this->usageNote = (string) ($element->usage_note ?? '');
$this->licenseNote = (string) ($element->license_note ?? '');
$this->kindId = $element->editorial_content_kind_id;
$this->pillarIds = $element->pillars()->pluck('pillars.id')->all();
$this->dimensionIds = IdentityDimensionValue::query()
->where('subject_type', $element->getMorphClass())
->where('subject_id', $element->id)
->where('origin', 'direkt')
->pluck('editorial_dimension_value_id')
->all();
}
}