Lege Bildfassungen an und liefere sie zwischengespeichert aus (ADR-63)
Vorschaubilder entstehen zusätzlich als klein (360 px) und mittel (960 px), Website-Bilder in den Breiten 640, 1280 und 1920. Auswahl, Listen und Karten laden die kleinen Fassungen; die Website nutzt srcset. Adressen tragen Größe und Version und werden dauerhaft zwischengespeichert (ETag, 304). Die Website-Route läuft ohne Sitzung und Cookies. Bestand füllt sich über die Warteschlange oder mit media:varianten. Die Optionsliste des CMS fragt nicht mehr je Eintrag ab. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0492133201
commit
63b42b366c
54 files changed
+1033
-82
No files matched your search
@@ -86,7 +86,7 @@ public function elementId(mixed $value): ?int
|
||||
return is_int($id) ? $id : null;
|
||||
}
|
||||
|
||||
public function presentation(mixed $value): ?WebsitePresentation
|
||||
public function presentation(mixed $value, ?ContentElement $loaded = null): ?WebsitePresentation
|
||||
{
|
||||
$id = $this->elementId($value);
|
||||
|
||||
@@ -95,7 +95,8 @@ public function presentation(mixed $value): ?WebsitePresentation
|
||||
}
|
||||
|
||||
if (! array_key_exists($id, $this->presentations)) {
|
||||
$this->presentations[$id] = $this->media->present($id) ?? false;
|
||||
// Ein schon geladenes Medium wird weitergereicht (kein zweiter Zugriff je Eintrag in der Auswahl).
|
||||
$this->presentations[$id] = $this->media->present($loaded?->getKey() === $id ? $loaded : $id) ?? false;
|
||||
}
|
||||
|
||||
return $this->presentations[$id] ?: null;
|
||||
@@ -105,12 +106,12 @@ public function presentation(mixed $value): ?WebsitePresentation
|
||||
* Bildadresse für die Darstellung. Öffentlich nur freigegebene Medien (oder frühere CMS-Bilder ohne Zuordnung);
|
||||
* in der Redaktionsvorschau zusätzlich das Vorschaubild eines nicht freigegebenen Mediums.
|
||||
*/
|
||||
public function url(mixed $value, bool $preview = false): ?string
|
||||
public function url(mixed $value, bool $preview = false, ?int $width = null): ?string
|
||||
{
|
||||
$presentation = $this->presentation($value);
|
||||
|
||||
if ($presentation !== null) {
|
||||
return $presentation->kind === 'bild' ? $presentation->url : null;
|
||||
return $presentation->kind === 'bild' ? $presentation->urlForWidth($width) : null;
|
||||
}
|
||||
|
||||
$id = $this->elementId($value);
|
||||
@@ -122,7 +123,7 @@ public function url(mixed $value, bool $preview = false): ?string
|
||||
|
||||
$element = ContentElement::query()->find($id);
|
||||
|
||||
return $element === null ? null : ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path);
|
||||
return $element === null ? null : ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'mittel', $element->updated_at);
|
||||
}
|
||||
|
||||
$legacy = self::normalize($value);
|
||||
@@ -134,6 +135,14 @@ public function url(mixed $value, bool $preview = false): ?string
|
||||
return is_string($legacy) ? PublicMedia::url($legacy) : null;
|
||||
}
|
||||
|
||||
/** `srcset` des freigegebenen Bildes (mehrere Breiten), sonst null. Für Hero, Bild mit Text, Karten. */
|
||||
public function srcset(mixed $value): ?string
|
||||
{
|
||||
$presentation = $this->presentation($value);
|
||||
|
||||
return $presentation !== null && $presentation->kind === 'bild' ? $presentation->srcset : null;
|
||||
}
|
||||
|
||||
/** Alternativtext: Angabe im Widget, sonst der Alternativtext des Mediums. */
|
||||
public function alt(mixed $value, mixed $override = null): string
|
||||
{
|
||||
@@ -169,7 +178,7 @@ public function previewNotice(mixed $value, string $label = 'Das gewählte Bild'
|
||||
*
|
||||
* @return array{public: bool, state: string, title: string, note: string, thumb: ?string, manageUrl: ?string}|null
|
||||
*/
|
||||
public function status(mixed $value): ?array
|
||||
public function status(mixed $value, ?ContentElement $loaded = null): ?array
|
||||
{
|
||||
$value = self::normalize($value);
|
||||
|
||||
@@ -194,16 +203,16 @@ public function status(mixed $value): ?array
|
||||
];
|
||||
}
|
||||
|
||||
$element = ContentElement::query()->with('editorialContentKind')->find($id);
|
||||
$element = $loaded?->getKey() === $id ? $loaded : ContentElement::query()->with('editorialContentKind')->find($id);
|
||||
|
||||
if ($element === null) {
|
||||
return ['public' => false, 'state' => 'missing', 'title' => 'Medium '.$id, 'note' => 'Das Medium gibt es nicht mehr.', 'thumb' => null, 'manageUrl' => null];
|
||||
}
|
||||
|
||||
$title = (string) ($element->display_title ?: $element->working_title);
|
||||
$thumb = ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path);
|
||||
$thumb = ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'klein', $element->updated_at);
|
||||
$manageUrl = ContentElementResource::getUrl('view', ['record' => $element]);
|
||||
$public = $this->presentation($id) !== null;
|
||||
$public = $this->presentation($id, $element) !== null;
|
||||
|
||||
$note = match (true) {
|
||||
$public => 'Für die Website freigegeben.',
|
||||
@@ -292,7 +301,7 @@ public function options(?string $search = null, int $limit = 60): array
|
||||
$options = [];
|
||||
foreach ($elements as $element) {
|
||||
if (self::isSelectable($element)) {
|
||||
$options[$element->id] = $this->optionHtml($element->id);
|
||||
$options[$element->id] = $this->optionHtml($element->id, $element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,9 +309,9 @@ public function options(?string $search = null, int $limit = 60): array
|
||||
}
|
||||
|
||||
/** HTML-Bezeichnung einer Option oder des gewählten Werts (auch für frühere Pfade). */
|
||||
public function optionHtml(mixed $value): ?string
|
||||
public function optionHtml(mixed $value, ?ContentElement $loaded = null): ?string
|
||||
{
|
||||
$status = $this->status($value);
|
||||
$status = $this->status($value, $loaded);
|
||||
|
||||
if ($status === null) {
|
||||
return null;
|
||||
@@ -315,7 +324,7 @@ public function optionHtml(mixed $value): ?string
|
||||
default => ['warn', 'Website: nicht freigegeben'],
|
||||
};
|
||||
$thumb = $status['thumb'] !== null
|
||||
? '<img src="'.e($status['thumb']).'" alt="" loading="lazy">'
|
||||
? '<img src="'.e($status['thumb']).'" alt="" loading="lazy" decoding="async">'
|
||||
: '<span class="luf-media-option-empty" aria-hidden="true"></span>';
|
||||
|
||||
return '<span class="luf-media-option">'.$thumb
|
||||
|
||||
Reference in new issue
Block a user