Ergänze die gemeinsame redaktionelle Basis an den Fachobjekten.
CI Feature / test (push) Successful in 54s
Deploy Test / test (push) Successful in 47s
Deploy Test / deploy (push) Successful in 24s

Texte, Materialart und Präsentationsmedien bleiben am Medium, Modul, Programm und Lizenzartikel und werden von Verwaltung und Karten aus derselben Quelle gelesen, ohne Fassung oder Lizenz zu verändern.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-19 07:54:36 +01:00
1 parent c4be6ed8dc
commit f29ea58fd5
40 files changed
+2311 -20

No files matched your search

+2
View File
@@ -11,8 +11,10 @@ class Composition extends Model
protected $fillable = [
'designation',
'display_title',
'teaser',
'summary',
'description',
'search_terms',
'thumbnail_path',
'thumbnail_alt',
'thumbnail_source',
+2
View File
@@ -14,6 +14,7 @@ class ContentElement extends Model
'output_class',
'working_title',
'display_title',
'teaser',
'description',
'usage_note',
'license_note',
@@ -22,6 +23,7 @@ class ContentElement extends Model
'website_released_at',
'website_public_path',
'summary',
'search_terms',
'thumbnail_path',
'thumbnail_alt',
'thumbnail_source',
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Model;
/**
* Aufgelöste Klasse-A-Angaben eines Fachobjekts.
* Fehlende Felder bleiben leer. Es wird nichts materialisiert.
*/
final readonly class EditorialProfile
{
/**
* @param array<string, ResolvedText> $texts
*/
public function __construct(
public ?string $workingTitle,
public array $texts,
public ?string $searchTerms,
public string $searchOrigin,
public ?string $kindLabel,
public ?Model $source,
) {}
public function text(string $field): ResolvedText
{
return $this->texts[$field] ?? new ResolvedText(null, 'leer', null);
}
public function value(string $field): ?string
{
return $this->text($field)->value;
}
public function origin(string $field): string
{
return $this->text($field)->origin;
}
public function originLabel(string $field): string
{
$text = $this->text($field);
return match ($text->origin) {
'eigen' => 'Eigene Angabe',
'variante' => 'Abweichung für '.($text->label ?? 'diesen Kontext'),
'quelle' => 'Übernommen von '.($text->label ?? 'der fachlichen Quelle'),
default => 'Keine Angabe',
};
}
}
@@ -0,0 +1,225 @@
<?php
namespace App\Domain\Catalog;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
/**
* Löst die Klasse-A-Texte eines Fachobjekts auf.
*
* Reihenfolge: abweichende Formulierung für den Kontext, eigene Angabe am Objekt,
* bei einem Lizenzartikel die Angabe der eindeutigen fachlichen Quelle.
* Eine Quelle gibt es nur, wenn der aktuelle Artikelstand genau eine Wurzel hat.
* Preise, Rechte und Fassungen werden nicht gelesen und nicht geschrieben.
*/
class EditorialProfileReader
{
public const AUDIENCES = [
'kachel' => 'Öffentliche Kachel',
'detail' => 'Öffentliche Detailvorstellung',
'bibliothek' => 'Mitgliederbibliothek',
'trainer' => 'Fachliche Traineransicht',
'artikel' => 'Lizenzartikelpräsentation',
'cms' => 'CMS-Teaser',
'suche' => 'Suchergebnis',
];
public const TEXT_FIELDS = ['display_title', 'teaser', 'summary', 'description'];
public function read(Model $subject, ?string $audience = null): EditorialProfile
{
if ($audience !== null && ! array_key_exists($audience, self::AUDIENCES)) {
throw new DomainRuleException('Diese Zielgruppe ist nicht vorgesehen.');
}
$source = $subject instanceof LicenseArticle ? $this->sourceOf($subject) : null;
$texts = [];
foreach (self::TEXT_FIELDS as $field) {
$texts[$field] = $this->resolve($subject, $field, $audience, $source);
}
$search = $this->own($subject, 'search_terms');
$searchOrigin = 'eigen';
if ($search === null && $source instanceof Model) {
$search = $this->own($source, 'search_terms');
$searchOrigin = $search === null ? 'leer' : 'quelle';
}
if ($search === null) {
$searchOrigin = 'leer';
}
return new EditorialProfile(
workingTitle: $this->workingTitle($subject),
texts: $texts,
searchTerms: $search,
searchOrigin: $searchOrigin,
kindLabel: $subject->editorialContentKind?->label
?? ($source?->editorialContentKind?->label),
source: $source,
);
}
public function sourceOf(LicenseArticle $article): ?Model
{
$release = $article->relationLoaded('currentRelease')
? $article->currentRelease
: $article->currentRelease()->first();
if (! $release instanceof ArticleRelease) {
return null;
}
$elementId = $release->root_element_version_id;
$compositionId = $release->root_composition_version_id;
if (($elementId === null) === ($compositionId === null)) {
return null;
}
if ($elementId !== null) {
return ContentElementVersion::query()->with('element.editorialContentKind')->find($elementId)?->element;
}
return CompositionVersion::query()->with('composition.editorialContentKind')->find($compositionId)?->composition;
}
public function putVariant(Model $subject, string $field, string $audience, ?string $body, ?User $actor = null): string
{
if (! in_array($field, self::TEXT_FIELDS, true) || ! array_key_exists($audience, self::AUDIENCES)) {
throw new DomainRuleException('Diese Abweichung ist nicht vorgesehen.');
}
$body = is_string($body) ? trim($body) : '';
$existing = $this->variant($subject, $field, $audience);
if ($body === '') {
if ($existing instanceof EditorialTextVariant) {
$this->record($subject, $audience, $field, $existing->body, null, $actor);
$existing->delete();
}
return 'Die abweichende Formulierung ist entfernt. Es gilt wieder die zentrale Angabe.';
}
if ($existing instanceof EditorialTextVariant && $existing->body === $body) {
return 'Die abweichende Formulierung ist unverändert.';
}
$this->record($subject, $audience, $field, $existing?->body, $body, $actor);
EditorialTextVariant::query()->updateOrCreate(
[
'subject_type' => $subject->getMorphClass(),
'subject_id' => $subject->getKey(),
'field' => $field,
'audience' => $audience,
],
['body' => $body],
);
return 'Die abweichende Formulierung gilt nur für '.self::AUDIENCES[$audience].'. Die zentrale Angabe bleibt.';
}
public function forgetVariant(Model $subject, EditorialTextVariant $variant, ?User $actor = null): void
{
if ($variant->subject_type !== $subject->getMorphClass() || (int) $variant->subject_id !== (int) $subject->getKey()) {
throw new DomainRuleException('Diese Abweichung gehört zu einem anderen Objekt.');
}
$this->record($subject, $variant->audience, $variant->field, $variant->body, null, $actor);
$variant->delete();
}
private function resolve(Model $subject, string $field, ?string $audience, ?Model $source): ResolvedText
{
if ($audience !== null) {
$variant = $this->variant($subject, $field, $audience);
if ($variant instanceof EditorialTextVariant && trim($variant->body) !== '') {
return new ResolvedText(trim($variant->body), 'variante', self::AUDIENCES[$audience]);
}
}
$own = $this->own($subject, $field);
if ($own !== null) {
return new ResolvedText($own, 'eigen', null);
}
if ($source instanceof Model) {
$fromSource = $this->resolve($source, $field, $audience, null);
if ($fromSource->value !== null) {
return new ResolvedText($fromSource->value, 'quelle', $this->sourceLabel($source));
}
}
return new ResolvedText(null, 'leer', null);
}
private function variant(Model $subject, string $field, string $audience): ?EditorialTextVariant
{
return EditorialTextVariant::query()
->where('subject_type', $subject->getMorphClass())
->where('subject_id', $subject->getKey())
->where('field', $field)
->where('audience', $audience)
->first();
}
private function own(Model $subject, string $field): ?string
{
$value = $subject->getAttribute($field);
if (! is_string($value)) {
return null;
}
$value = trim($value);
return $value === '' ? null : $value;
}
private function workingTitle(Model $subject): ?string
{
if ($subject instanceof Composition) {
return $this->own($subject, 'designation');
}
if ($subject instanceof LicenseArticle) {
return $this->own($subject, 'working_title') ?? $this->own($subject, 'code');
}
return $this->own($subject, 'working_title');
}
private function sourceLabel(Model $source): string
{
if ($source instanceof Composition) {
return (string) ($source->display_title ?: $source->designation);
}
if ($source instanceof ContentElement) {
return (string) ($source->display_title ?: $source->working_title);
}
return 'der fachlichen Quelle';
}
private function record(Model $subject, string $audience, string $field, ?string $before, ?string $after, ?User $actor): void
{
IdentityChange::query()->create([
'subject_type' => $subject->getMorphClass(),
'subject_id' => $subject->getKey(),
'field' => 'variante:'.$audience.':'.$field,
'before' => $before,
'after' => $after,
'actor_id' => $actor?->id,
'occurred_at' => now(),
]);
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Model;
class EditorialTextVariant extends Model
{
protected $fillable = [
'subject_type',
'subject_id',
'field',
'audience',
'body',
];
}
+12
View File
@@ -10,6 +10,13 @@ class LicenseArticle extends Model
{
protected $fillable = [
'code',
'working_title',
'display_title',
'teaser',
'summary',
'description',
'search_terms',
'editorial_content_kind_id',
'product_line',
'successor_of_id',
'current_release_id',
@@ -37,4 +44,9 @@ public function successorOf(): BelongsTo
{
return $this->belongsTo(self::class, 'successor_of_id');
}
public function editorialContentKind(): BelongsTo
{
return $this->belongsTo(EditorialContentKind::class);
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PresentationAssignment extends Model
{
protected $fillable = [
'subject_type',
'subject_id',
'content_element_id',
'presentation_role_id',
'position',
'source_version_id',
];
public function role(): BelongsTo
{
return $this->belongsTo(PresentationRole::class, 'presentation_role_id');
}
public function element(): BelongsTo
{
return $this->belongsTo(ContentElement::class, 'content_element_id');
}
public function sourceVersion(): BelongsTo
{
return $this->belongsTo(ContentElementVersion::class, 'source_version_id');
}
}
+269
View File
@@ -0,0 +1,269 @@
<?php
namespace App\Domain\Catalog;
use App\Domain\Media\WebsiteMedia;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
/**
* Präsentationsmedien sind Referenzen auf Inhaltselemente.
* Die Rolle gehört zur Zuordnung. Eine Zuordnung gibt nichts frei und ändert keine Fassung.
*/
class PresentationMedia
{
public function __construct(private readonly WebsiteMedia $website) {}
/**
* @return list<array<string, mixed>>
*/
public function rows(Model $subject): array
{
$assignments = PresentationAssignment::query()
->with(['role', 'element.editorialContentKind', 'sourceVersion'])
->where('subject_type', $subject->getMorphClass())
->where('subject_id', $subject->getKey())
->orderBy('position')
->orderBy('id')
->get();
$rows = [];
foreach ($assignments as $assignment) {
$element = $assignment->element;
$released = $element instanceof ContentElement && $this->website->present($element) !== null;
$binding = $this->binding($assignment);
$rows[] = [
'id' => $assignment->id,
'role' => (string) $assignment->role?->slug,
'role_label' => (string) ($assignment->role?->label ?? ''),
'ordered' => (bool) $assignment->role?->ordered,
'position' => (int) $assignment->position,
'standard' => $assignment->role?->slug === 'titelbild',
'element_id' => (int) $assignment->content_element_id,
'title' => $element instanceof ContentElement
? (string) ($element->display_title ?: $element->working_title)
: 'Medium fehlt',
'kind' => $element?->editorialContentKind?->label,
'output' => $element instanceof ContentElement ? (string) $element->output_class : '',
'released' => $released,
'release_label' => $released ? 'Für die Website freigegeben' : 'Nicht für die Website freigegeben',
'binding' => $binding,
];
}
return $rows;
}
public function assign(Model $subject, string $roleSlug, int $elementId, ?int $sourceVersionId, ?User $actor = null): string
{
$role = PresentationRole::query()->where('slug', $roleSlug)->first();
$element = ContentElement::query()->find($elementId);
if (! $role instanceof PresentationRole || ! $element instanceof ContentElement) {
throw new DomainRuleException('Rolle oder Medium fehlt.');
}
if ($element->archived_at !== null) {
throw new DomainRuleException('Ein archiviertes Medium wird nicht zugeordnet.');
}
if ($subject instanceof ContentElement && (int) $subject->getKey() === (int) $element->id) {
throw new DomainRuleException('Ein Medium kann nicht seine eigene Präsentation sein.');
}
$source = $this->checkedSource($subject, $element, $sourceVersionId);
$existing = PresentationAssignment::query()
->where('subject_type', $subject->getMorphClass())
->where('subject_id', $subject->getKey())
->where('presentation_role_id', $role->id)
->where('content_element_id', $element->id)
->first();
if ($existing instanceof PresentationAssignment) {
if ((int) $existing->source_version_id !== (int) ($source?->id ?? 0) && ($source !== null || $existing->source_version_id !== null)) {
$existing->source_version_id = $source?->id;
$existing->save();
$this->record($subject, null, $role->label.': '.$element->working_title, $actor);
}
return $element->working_title.' ist in dieser Rolle bereits zugeordnet.';
}
if (! $role->multiple) {
PresentationAssignment::query()
->where('subject_type', $subject->getMorphClass())
->where('subject_id', $subject->getKey())
->where('presentation_role_id', $role->id)
->delete();
}
$position = (int) PresentationAssignment::query()
->where('subject_type', $subject->getMorphClass())
->where('subject_id', $subject->getKey())
->where('presentation_role_id', $role->id)
->max('position') + 1;
PresentationAssignment::query()->create([
'subject_type' => $subject->getMorphClass(),
'subject_id' => $subject->getKey(),
'content_element_id' => $element->id,
'presentation_role_id' => $role->id,
'position' => max(1, $position),
'source_version_id' => $source?->id,
]);
$this->record($subject, null, $role->label.': '.$element->working_title, $actor);
return $element->working_title.' ist als '.$role->label.' zugeordnet. Es entsteht keine Fassung und keine Freigabe.';
}
public function detach(Model $subject, int $assignmentId, ?User $actor = null): string
{
$assignment = $this->owned($subject, $assignmentId);
$label = ($assignment->role?->label ?? 'Präsentation').': '.($assignment->element?->working_title ?? '');
$assignment->delete();
$this->record($subject, $label, null, $actor);
return 'Die Zuordnung ist entfernt. Das Medium bleibt im Bestand.';
}
public function move(Model $subject, int $assignmentId, int $direction, ?User $actor = null): void
{
$assignment = $this->owned($subject, $assignmentId);
if (! $assignment->role?->ordered || $direction === 0) {
return;
}
$neighbors = PresentationAssignment::query()
->where('subject_type', $subject->getMorphClass())
->where('subject_id', $subject->getKey())
->where('presentation_role_id', $assignment->presentation_role_id)
->orderBy('position')
->orderBy('id')
->get()
->values();
$index = $neighbors->search(fn (PresentationAssignment $row): bool => $row->id === $assignment->id);
if ($index === false) {
return;
}
$swap = $index + ($direction < 0 ? -1 : 1);
$other = $neighbors->get($swap);
if (! $other instanceof PresentationAssignment) {
return;
}
$position = $assignment->position;
$assignment->position = $other->position === $position ? $position + ($direction < 0 ? -1 : 1) : $other->position;
$other->position = $position;
$assignment->save();
$other->save();
$this->record($subject, null, 'Reihenfolge '.$assignment->role?->label, $actor);
}
/**
* Kennung des ersten Titel- oder Galeriebildes. Ob es öffentlich erscheint, entscheidet WebsiteMedia.
*/
public function coverElementId(Model $subject): ?int
{
$assignments = PresentationAssignment::query()
->with('role')
->where('subject_type', $subject->getMorphClass())
->where('subject_id', $subject->getKey())
->orderBy('position')
->get();
foreach (PresentationRole::COVER_ROLES as $slug) {
$match = $assignments->first(fn (PresentationAssignment $row): bool => $row->role?->slug === $slug);
if ($match instanceof PresentationAssignment) {
return (int) $match->content_element_id;
}
}
return null;
}
private function owned(Model $subject, int $assignmentId): PresentationAssignment
{
$assignment = PresentationAssignment::query()
->with(['role', 'element'])
->where('subject_type', $subject->getMorphClass())
->where('subject_id', $subject->getKey())
->whereKey($assignmentId)
->first();
if (! $assignment instanceof PresentationAssignment) {
throw new DomainRuleException('Diese Zuordnung gehört zu einem anderen Objekt.');
}
return $assignment;
}
private function checkedSource(Model $subject, ContentElement $element, ?int $sourceVersionId): ?ContentElementVersion
{
if ($sourceVersionId === null) {
return null;
}
$version = ContentElementVersion::query()->find($sourceVersionId);
if (! $version instanceof ContentElementVersion) {
throw new DomainRuleException('Die gebundene Fassung fehlt.');
}
$ownsFilm = $subject instanceof ContentElement && (int) $version->content_element_id === (int) $subject->getKey();
$ownsClip = (int) $version->content_element_id === (int) $element->id;
if (! $ownsFilm && ! $ownsClip) {
throw new DomainRuleException('Die gebundene Fassung gehört weder zum Fachobjekt noch zum zugeordneten Medium.');
}
return $version;
}
/**
* @return array{label: string, stale: bool}|null
*/
private function binding(PresentationAssignment $assignment): ?array
{
if ($assignment->source_version_id === null || ! $assignment->sourceVersion instanceof ContentElementVersion) {
return null;
}
$version = $assignment->sourceVersion;
$latestId = ContentElementVersion::query()
->where('content_element_id', $version->content_element_id)
->where('status', ContentVersionStatus::Bereit)
->orderByDesc('number')
->value('id');
$stale = $latestId !== null && (int) $latestId !== (int) $version->id;
return [
'label' => $stale
? 'Gebunden an Fassung '.$version->number.'. Die aktuelle Fassung ist eine andere. Der Clip wurde nicht neu erzeugt.'
: 'Gebunden an Fassung '.$version->number.'.',
'stale' => $stale,
];
}
private function record(Model $subject, ?string $before, ?string $after, ?User $actor): void
{
IdentityChange::query()->create([
'subject_type' => $subject->getMorphClass(),
'subject_id' => $subject->getKey(),
'field' => 'praesentation',
'before' => $before,
'after' => $after,
'actor_id' => $actor?->id,
'occurred_at' => now(),
]);
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class PresentationRole extends Model
{
/** Rollen, deren Herkunft an einer Film- oder Audiofassung festgehalten werden kann. */
public const BOUND_ROLES = ['trailer', 'vorschauclip', 'audiovorschau'];
/** Reihenfolge, in der ein öffentliches Titelbild gesucht wird. */
public const COVER_ROLES = ['titelbild', 'hero', 'hover', 'titelbild_alternativ', 'galerie'];
protected $fillable = [
'slug',
'label',
'multiple',
'ordered',
'sort_order',
];
protected function casts(): array
{
return [
'multiple' => 'boolean',
'ordered' => 'boolean',
];
}
public function assignments(): HasMany
{
return $this->hasMany(PresentationAssignment::class);
}
/**
* @return array<string, string>
*/
public static function selectOptions(): array
{
return static::query()->orderBy('sort_order')->pluck('label', 'slug')->all();
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace App\Domain\Catalog;
/**
* Ein aufgelöster redaktioneller Text. Der Wert wird nicht kopiert:
* eigen steht am Fachobjekt, variante ist eine Abweichung für einen Kontext,
* quelle verweist auf das eindeutig zugeordnete Fachobjekt eines Lizenzartikels.
*/
final readonly class ResolvedText
{
public function __construct(
public ?string $value,
public string $origin,
public ?string $label,
) {}
}
+19
View File
@@ -37,4 +37,23 @@ public function __construct(
public array $missing = [],
public ?string $style = null,
) {}
public function withText(?string $title, ?string $summary): self
{
return new self(
title: $title ?? $this->title,
summary: $summary ?? $this->summary,
kind: $this->kind,
badge: $this->badge,
meta: $this->meta,
url: $this->url,
public: $this->public,
notice: $this->notice,
visual: $this->visual,
visualLabel: $this->visualLabel,
previewImage: $this->previewImage,
missing: $this->missing,
style: $this->style,
);
}
}
+10 -4
View File
@@ -7,6 +7,7 @@
use App\Domain\Catalog\CompositionVersion;
use App\Domain\Catalog\ContentVersionStatus;
use App\Domain\Catalog\EditorialContentKind;
use App\Domain\Catalog\EditorialProfileReader;
use App\Domain\Media\ThumbnailRef;
use Illuminate\Support\Collection;
@@ -95,7 +96,9 @@ public function search(?string $term, int $limit = 25): array
$like = '%'.mb_strtolower($term).'%';
$query->where(fn ($inner) => $inner
->whereRaw('LOWER(designation) LIKE ?', [$like])
->orWhereRaw('LOWER(COALESCE(display_title, \'\')) LIKE ?', [$like]));
->orWhereRaw('LOWER(COALESCE(display_title, \'\')) LIKE ?', [$like])
->orWhereRaw('LOWER(COALESCE(teaser, \'\')) LIKE ?', [$like])
->orWhereRaw('LOWER(COALESCE(search_terms, \'\')) LIKE ?', [$like]));
})
->orderBy('designation')
->limit($limit * 3)
@@ -200,7 +203,9 @@ public function cardSearch(?string $term, int $limit = 25): array
$like = '%'.mb_strtolower($term).'%';
$query->where(fn ($inner) => $inner
->whereRaw('LOWER(designation) LIKE ?', [$like])
->orWhereRaw('LOWER(COALESCE(display_title, \'\')) LIKE ?', [$like]));
->orWhereRaw('LOWER(COALESCE(display_title, \'\')) LIKE ?', [$like])
->orWhereRaw('LOWER(COALESCE(teaser, \'\')) LIKE ?', [$like])
->orWhereRaw('LOWER(COALESCE(search_terms, \'\')) LIKE ?', [$like]));
})
->orderBy('designation')
->limit($limit * 3)
@@ -257,7 +262,8 @@ public function subject(mixed $id, bool $includeNonPublic): ?CardSubject
$version = $shown ?? $this->latestReadyVersion($composition);
$program = $composition->editorialContentKind?->slug === 'programm';
$kind = (string) ($composition->editorialContentKind?->label ?? ($program ? 'Programm' : 'Modul'));
$summary = filled($composition->summary) ? trim((string) $composition->summary) : null;
$profile = app(EditorialProfileReader::class)->read($composition, 'kachel');
$summary = $profile->value('teaser') ?: $profile->value('summary');
$goal = filled($version?->learning_goal) ? trim((string) $version->learning_goal) : null;
$missing = [];
@@ -295,7 +301,7 @@ public function subject(mixed $id, bool $includeNonPublic): ?CardSubject
}
return new CardSubject(
title: $this->title($composition),
title: $profile->value('display_title') ?: $this->title($composition),
summary: $summary ?? $goal,
kind: $kind,
badge: null,
@@ -5,6 +5,7 @@
use App\Domain\Catalog\CompositionStructureReader;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentVersionStatus;
use App\Domain\Catalog\EditorialProfileReader;
use App\Domain\Catalog\StructureNode;
use App\Domain\Media\ThumbnailRef;
@@ -137,6 +138,19 @@ public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ?
$film = $shown->output_class === 'film';
$editorialKind = $element->editorialContentKind?->label;
$summary = filled($shown->summary) ? trim((string) $shown->summary) : null;
$profile = app(EditorialProfileReader::class)->read($shown, 'bibliothek');
if (! array_key_exists('summary', $draft) && $profile->origin('summary') === 'variante') {
$summary = $profile->value('summary');
} elseif ($summary === null && filled($shown->teaser)) {
$summary = trim((string) $shown->teaser);
}
$title = (string) ($shown->display_title ?: $shown->working_title);
if (! array_key_exists('display_title', $draft) && $profile->origin('display_title') === 'variante') {
$title = (string) $profile->value('display_title');
}
$meta = [$output];
if ($program !== null) {
@@ -157,7 +171,7 @@ public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ?
$previewImage = $includeNonPublic ? ThumbnailRef::url('editorial.card', 'element', (int) $element->id, $shown->thumbnail_path) : null;
return new CardSubject(
title: (string) ($shown->display_title ?: $shown->working_title),
title: $title,
summary: $summary,
kind: filled($editorialKind) ? (string) $editorialKind : $output,
badge: $output,
@@ -3,6 +3,7 @@
namespace App\Domain\Cms\Widgets\Types;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\PresentationMedia;
use App\Domain\Cms\Catalog\CardSubject;
use App\Domain\Cms\Catalog\PublicMaterialReader;
use App\Domain\Cms\Widgets\RenderContext;
@@ -88,4 +89,13 @@ protected function cardStyle(): string
{
return 'media';
}
protected function centralCoverId(mixed $id): ?int
{
$element = is_numeric($id) ? ContentElement::query()->find((int) $id) : null;
return $element instanceof ContentElement
? app(PresentationMedia::class)->coverElementId($element)
: null;
}
}
@@ -137,6 +137,8 @@ public function dataRules(): array
return [
'action_label' => ['nullable', 'string', 'max:60'],
'note' => ['nullable', 'string', 'max:200'],
'heading' => ['nullable', 'string', 'max:200'],
'summary' => ['nullable', 'string', 'max:500'],
'alt' => ['nullable', 'string', 'max:300'],
'focus_x' => ['nullable', 'numeric', 'between:0,100'],
'focus_y' => ['nullable', 'numeric', 'between:0,100'],
@@ -178,7 +180,22 @@ public function editorSchema(): array
return [
Group::make([$this->subjectField()])->statePath('refs'),
Group::make([$action, $note])->statePath('data'),
Group::make([
$action,
$note,
TextInput::make('heading')
->label('Anzeigename nur für diese Karte')
->maxLength(200)
->live(onBlur: true)
->placeholder('Zentraler Anzeigename')
->helperText('Leer übernimmt den Anzeigenamen des Fachobjekts. Eine Eintragung gilt nur für diese Karte und ändert die Quelle nicht.'),
TextInput::make('summary')
->label('Teaser nur für diese Karte')
->maxLength(500)
->live(onBlur: true)
->placeholder('Zentraler Teaser oder Kurzbeschreibung')
->helperText('Leer übernimmt Teaser oder Kurzbeschreibung. Lehrinhalt, Rechte und Preise bleiben unberührt.'),
])->statePath('data'),
];
}
@@ -205,7 +222,7 @@ public function clean(array $data, array $refs, WidgetErrors $errors): array
$refs[$key] = $id;
$refs = ImageRefFields::clean($refs, $errors);
foreach (['action_label', 'note', 'alt'] as $field) {
foreach (['action_label', 'note', 'alt', 'heading', 'summary'] as $field) {
$data[$field] = filled($data[$field] ?? null) ? trim((string) $data[$field]) : null;
}
@@ -224,13 +241,22 @@ public function resolve(array $widget, RenderContext $context): array
$data = $widget['data'];
$subject = $this->subject($widget['refs'][$this->refKey()] ?? null, $context);
$heading = filled($data['heading'] ?? null) ? trim((string) $data['heading']) : null;
$lead = filled($data['summary'] ?? null) ? trim((string) $data['summary']) : null;
if ($subject instanceof CardSubject && ($heading !== null || $lead !== null)) {
$subject = $subject->withText($heading, $lead);
}
$storedImage = WebsiteImage::normalize($widget['refs']['image'] ?? null);
$imageRef = $storedImage ?? $this->centralCoverId($widget['refs'][$this->refKey()] ?? null);
return [
'subject' => $subject,
'cardStyle' => $subject?->style ?? $this->cardStyle(),
'imageUrl' => app(WebsiteImage::class)->url($widget['refs']['image'] ?? null, $context->preview),
'alt' => app(WebsiteImage::class)->alt($widget['refs']['image'] ?? null, $data['alt'] ?? null),
'imageNotice' => $context->preview ? app(WebsiteImage::class)->previewNotice($widget['refs']['image'] ?? null, 'Das Kartenbild') : null,
'imageUrl' => app(WebsiteImage::class)->url($imageRef, $context->preview),
'alt' => app(WebsiteImage::class)->alt($imageRef, $data['alt'] ?? null),
'imageNotice' => $context->preview ? app(WebsiteImage::class)->previewNotice($imageRef, 'Das Kartenbild') : null,
'focus' => PremiumFields::focus($data, 66, 45),
'format' => $option('format', 'landscape'),
'fit' => $option('fit', 'cover'),
@@ -261,6 +287,11 @@ public function summary(array $widget): string
return $label ?? 'Kein Objekt gewählt';
}
protected function centralCoverId(mixed $id): ?int
{
return null;
}
private function subjectField(): Select
{
return Select::make($this->refKey())
@@ -3,6 +3,7 @@
namespace App\Domain\Cms\Widgets\Types;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\PresentationMedia;
use App\Domain\Cms\Catalog\CardSubject;
use App\Domain\Cms\Catalog\PublicCatalogReader;
use App\Domain\Cms\Widgets\RenderContext;
@@ -97,4 +98,13 @@ protected function cardStyle(): string
{
return 'catalog';
}
protected function centralCoverId(mixed $id): ?int
{
$composition = is_numeric($id) ? Composition::query()->find((int) $id) : null;
return $composition instanceof Composition
? app(PresentationMedia::class)->coverElementId($composition)
: null;
}
}