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>
653 lines
24 KiB
PHP
653 lines
24 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\ContentElements\Pages;
|
|
|
|
use App\Domain\Catalog\ContentElement;
|
|
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\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\Textarea;
|
|
use Filament\Resources\Pages\ViewRecord;
|
|
use Filament\Schemas\Components\View;
|
|
use Filament\Schemas\Schema;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
use Illuminate\Support\Collection;
|
|
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
|
use Livewire\WithFileUploads;
|
|
|
|
class ViewContentElement extends ViewRecord
|
|
{
|
|
use ReportsDomainRules;
|
|
use WithFileUploads;
|
|
|
|
protected static string $resource = ContentElementResource::class;
|
|
|
|
public ?int $fassung = null;
|
|
|
|
public string $frameSecond = '';
|
|
|
|
public string $bodyDraft = '';
|
|
|
|
public string $thumbnailAlt = '';
|
|
|
|
public string $pictureFeedback = '';
|
|
|
|
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);
|
|
|
|
$requested = request()->integer('fassung');
|
|
|
|
if ($requested > 0) {
|
|
$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 '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
|
|
{
|
|
return $schema->components([
|
|
View::make('filament.media.viewer')->viewData(fn (): array => $this->viewerData()),
|
|
]);
|
|
}
|
|
|
|
public function showVersion(int $version): void
|
|
{
|
|
abort_unless($this->ownedVersion($version) instanceof ContentElementVersion, 404);
|
|
$this->fassung = $version;
|
|
$this->syncBodyDraft();
|
|
}
|
|
|
|
public function saveShownText(): void
|
|
{
|
|
$shown = $this->shownVersion();
|
|
|
|
if (! ContentElementResource::editor() || ! $shown instanceof ContentElementVersion || $shown->element?->output_class !== 'text') {
|
|
return;
|
|
}
|
|
|
|
$created = app(ContentService::class)->isCommitted($shown);
|
|
$this->report(function () use ($shown): void {
|
|
app(ContentService::class)->reviseElementContent($shown, $this->bodyDraft);
|
|
}, $created
|
|
? 'Die neue Fassung ist angelegt. Die bisherige bleibt erhalten.'
|
|
: 'Der Text ist in derselben Fassung gespeichert.');
|
|
$this->getRecord()->unsetRelation('versions');
|
|
$this->syncBodyDraft();
|
|
}
|
|
|
|
public function adoptFrame(): void
|
|
{
|
|
abort_unless(ContentElementResource::editor(), 403);
|
|
/** @var ContentElement $element */
|
|
$element = $this->getRecord();
|
|
$shown = $this->shownVersion();
|
|
|
|
if (! $shown instanceof ContentElementVersion || $element->output_class !== 'film') {
|
|
$this->pictureFeedback = 'Für dieses Medium gibt es keine Filmstelle.';
|
|
|
|
return;
|
|
}
|
|
|
|
if (! is_numeric($this->frameSecond) || trim($this->frameSecond) === '') {
|
|
$this->pictureFeedback = 'Wähle zuerst eine Zeitposition.';
|
|
|
|
return;
|
|
}
|
|
|
|
$seconds = (float) $this->frameSecond;
|
|
|
|
if ($seconds < 0 || $seconds > 7200) {
|
|
$this->pictureFeedback = 'Die Zeitposition liegt außerhalb des Films.';
|
|
|
|
return;
|
|
}
|
|
|
|
$this->keepAlt($element);
|
|
$element->thumbnail_error = null;
|
|
$element->save();
|
|
DeriveThumbnail::dispatch('element', $element->id, null, null, $shown->id, $seconds);
|
|
$element->refresh();
|
|
$this->pictureFeedback = $element->thumbnail_error
|
|
?: 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.';
|
|
}
|
|
|
|
public function storePreview(): void
|
|
{
|
|
abort_unless(ContentElementResource::editor(), 403);
|
|
|
|
if (! $this->previewUpload instanceof TemporaryUploadedFile) {
|
|
$this->pictureFeedback = 'Wähle zuerst eine Bilddatei.';
|
|
|
|
return;
|
|
}
|
|
|
|
$extension = strtolower($this->previewUpload->getClientOriginalExtension());
|
|
|
|
if (! in_array($extension, ['png', 'jpg', 'jpeg', 'webp'], true)) {
|
|
$this->pictureFeedback = 'Das Vorschaubild muss eine Bilddatei sein.';
|
|
|
|
return;
|
|
}
|
|
|
|
$path = $this->previewUpload->storeAs(
|
|
'vorschau',
|
|
'karte-'.bin2hex(random_bytes(4)).'.'.$extension,
|
|
'cms_incoming',
|
|
);
|
|
$this->previewUpload = null;
|
|
|
|
if (! is_string($path)) {
|
|
$this->pictureFeedback = 'Das Vorschaubild wurde nicht übernommen.';
|
|
|
|
return;
|
|
}
|
|
|
|
$this->savePreviewImage($path);
|
|
}
|
|
|
|
public function savePreviewImage(string $path): void
|
|
{
|
|
abort_unless(ContentElementResource::editor(), 403);
|
|
/** @var ContentElement $element */
|
|
$element = $this->getRecord();
|
|
$this->keepAlt($element);
|
|
$element->thumbnail_error = null;
|
|
$element->save();
|
|
DeriveThumbnail::dispatch('element', $element->id, $path);
|
|
$element->refresh();
|
|
$this->pictureFeedback = $element->thumbnail_error
|
|
?: 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.';
|
|
}
|
|
|
|
public function useOwnImage(): void
|
|
{
|
|
abort_unless(ContentElementResource::editor(), 403);
|
|
/** @var ContentElement $element */
|
|
$element = $this->getRecord();
|
|
|
|
if ($element->output_class !== 'bild') {
|
|
$this->pictureFeedback = 'Die Datei dieses Mediums ist kein Bild. Lade ein Vorschaubild hoch.';
|
|
|
|
return;
|
|
}
|
|
|
|
$this->keepAlt($element);
|
|
$element->thumbnail_error = null;
|
|
$element->save();
|
|
DeriveThumbnail::dispatch('element', $element->id);
|
|
$element->refresh();
|
|
$this->pictureFeedback = $element->thumbnail_error
|
|
?: 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.';
|
|
}
|
|
|
|
public function framePreviewUrl(): ?string
|
|
{
|
|
$shown = $this->shownVersion();
|
|
|
|
if (! $shown instanceof ContentElementVersion || ! is_numeric($this->frameSecond) || trim($this->frameSecond) === '') {
|
|
return null;
|
|
}
|
|
|
|
return route('editorial.frame', [
|
|
'version' => $shown->id,
|
|
'sekunde' => $this->frameSecond,
|
|
]);
|
|
}
|
|
|
|
public function deactivateAction(): Action
|
|
{
|
|
return Action::make('deactivate')
|
|
->label('Deaktivieren')
|
|
->modalHeading('Fassung deaktivieren')
|
|
->modalDescription('Die Fassung bleibt hier einsehbar. Sie wird nicht mehr ausgeliefert und kann nicht in eine neue Übung oder einen neuen Kurs übernommen werden.')
|
|
->modalSubmitActionLabel('Deaktivieren')
|
|
->visible(fn (): bool => ContentElementResource::editor())
|
|
->schema([
|
|
Textarea::make('reason')->label('Begründung')->required(),
|
|
])
|
|
->action(function (array $data, array $arguments): void {
|
|
abort_unless(ContentElementResource::editor(), 403);
|
|
$this->report(function () use ($data, $arguments): void {
|
|
$version = $this->ownedVersion((int) ($arguments['version'] ?? 0));
|
|
abort_unless($version instanceof ContentElementVersion, 404);
|
|
app(ContentService::class)->block($version, (string) $data['reason']);
|
|
}, 'Die Fassung ist deaktiviert.');
|
|
$this->getRecord()->unsetRelation('versions');
|
|
});
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Action::make('releaseVersion')
|
|
->label('Fassung freigeben')
|
|
->modalHeading('Fassung freigeben')
|
|
->modalDescription('Diese Fassung wird freigegeben. Sie erscheint dadurch nicht in der Mitgliederbibliothek, nicht auf der Website und nicht in einem Angebot. Eine deaktivierte Fassung bleibt unverändert.')
|
|
->modalSubmitActionLabel('Freigeben')
|
|
->visible(function (): bool {
|
|
/** @var ContentElement $element */
|
|
$element = $this->getRecord();
|
|
|
|
return ContentElementResource::editor()
|
|
&& $element->versions()->where('status', ContentVersionStatus::Entwurf)->exists();
|
|
})
|
|
->action(function (array $arguments): void {
|
|
abort_unless(ContentElementResource::editor(), 403);
|
|
$this->report(function () use ($arguments): string {
|
|
/** @var ContentElement $element */
|
|
$element = $this->getRecord();
|
|
$versionId = (int) ($arguments['version'] ?? 0);
|
|
$version = $versionId > 0
|
|
? $this->ownedVersion($versionId)
|
|
: $element->versions()->where('status', ContentVersionStatus::Entwurf)->orderByDesc('number')->first();
|
|
abort_unless($version instanceof ContentElementVersion, 404);
|
|
$released = app(ContentService::class)->releaseElementVersion($version);
|
|
|
|
return 'Fassung '.$released->number.' ist freigegeben.';
|
|
}, 'Die Fassung ist freigegeben.');
|
|
$this->getRecord()->unsetRelation('versions');
|
|
}),
|
|
Action::make('revise')
|
|
->label('Neue Fassung anlegen')
|
|
->visible(fn (): bool => ContentElementResource::editor())
|
|
->schema(fn (): array => ElementRevision::fields($this->getRecord()))
|
|
->action(function (array $data): void {
|
|
$this->report(function () use ($data): string {
|
|
/** @var ContentElement $element */
|
|
$element = $this->getRecord();
|
|
|
|
return ElementRevision::publish($element, $data);
|
|
}, 'Die neue Fassung ist angelegt.');
|
|
$this->getRecord()->unsetRelation('versions');
|
|
}),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array{element: ContentElement, versions: Collection<int, ContentElementVersion>, shown: ?ContentElementVersion, fileUrl: ?string, pending: bool, pillars: list<string>, usage: list<string>, canRevise: bool}
|
|
*/
|
|
private function viewerData(): array
|
|
{
|
|
/** @var ContentElement $element */
|
|
$element = $this->getRecord();
|
|
$versions = $element->versions()->orderByDesc('number')->get();
|
|
$shown = $versions->firstWhere('id', $this->fassung)
|
|
?? $versions->first(fn (ContentElementVersion $version): bool => $version->status === ContentVersionStatus::Bereit)
|
|
?? $versions->first();
|
|
$preview = app(ContentPreviewController::class);
|
|
$committed = $shown instanceof ContentElementVersion && app(ContentService::class)->isCommitted($shown);
|
|
|
|
return [
|
|
'element' => $element,
|
|
'versions' => $versions,
|
|
'shown' => $shown,
|
|
'fileUrl' => $shown === null ? null : $preview->fileUrl($shown),
|
|
'pending' => $shown !== null && $preview->isPending($shown),
|
|
'pillars' => $element->pillars->pluck('name')->all(),
|
|
'usage' => app(CatalogReading::class)->elementUsage($element),
|
|
'canRevise' => ContentElementResource::editor(),
|
|
'canEditBody' => ContentElementResource::editor()
|
|
&& $shown instanceof ContentElementVersion
|
|
&& $element->output_class === 'text'
|
|
&& $shown->status !== ContentVersionStatus::Gesperrt,
|
|
'bodyCommitted' => $committed,
|
|
'pictureUrl' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path),
|
|
'pictureCaption' => $this->pictureCaption($element),
|
|
];
|
|
}
|
|
|
|
private function syncBodyDraft(): void
|
|
{
|
|
$this->bodyDraft = (string) ($this->shownVersion()?->body ?? '');
|
|
}
|
|
|
|
private function shownVersion(): ?ContentElementVersion
|
|
{
|
|
/** @var ContentElement $element */
|
|
$element = $this->getRecord();
|
|
$versions = $element->versions()->orderByDesc('number')->get();
|
|
|
|
return $versions->firstWhere('id', $this->fassung)
|
|
?? $versions->first(fn (ContentElementVersion $version): bool => $version->status === ContentVersionStatus::Bereit)
|
|
?? $versions->first();
|
|
}
|
|
|
|
private function keepAlt(ContentElement $element): void
|
|
{
|
|
$alt = trim($this->thumbnailAlt);
|
|
|
|
if ($alt === '') {
|
|
return;
|
|
}
|
|
|
|
$element->thumbnail_alt = $alt;
|
|
}
|
|
|
|
private function pictureCaption(ContentElement $element): string
|
|
{
|
|
$source = $element->thumbnail_source;
|
|
|
|
if (! is_string($source) || $source === '') {
|
|
return '';
|
|
}
|
|
|
|
if (preg_match('/^frame:\d+@([\d.]+)$/', $source, $match) === 1) {
|
|
return 'Vorschaubild aus dem Film bei '.$match[1].' Sekunden.';
|
|
}
|
|
|
|
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 => '',
|
|
};
|
|
}
|
|
|
|
private function ownedVersion(int $id): ?ContentElementVersion
|
|
{
|
|
/** @var ContentElement $element */
|
|
$element = $this->getRecord();
|
|
|
|
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();
|
|
}
|
|
}
|