Biete in Bild und Text einen Bildanteil, Bild ohne Text und ein Video auf dem Bild an
Neue Einstellung "Bildanteil" (Bild zu Text von 1:2 bis 2:1, nur im zweispaltigen Stand ab 900 px; ohne Wert bleibt die bisherige Verteilung). Der Text ist nur noch Pflicht, solange kein Bild gewählt ist; ein Bild darf allein über die ganze Breite stehen. Optional ein Video (refs.video, ein Film aus dem Medienmanager, gewählt über den gemeinsamen Picker): Der für die Website freigegebene Clip spielt auf dem Bild beim Überfahren stumm und per Klick mit Ton wie auf der Medienkarte (CardClip, card-clip.js). Ohne Versionssprung; gespeicherte Seiten bleiben unverändert. Die Pflichtregel für den Text wird bewusst gelockert: "Bitte einen Text eingeben" gilt nur noch ohne Bild. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3cf3e822b8
commit
5233b96c42
15 files changed
+603
-19
No files matched your search
@@ -120,6 +120,12 @@ public function resolve(mixed $id, bool $preview): array
|
||||
];
|
||||
}
|
||||
|
||||
/** Ein Film, der nicht archiviert, nicht gesperrt und keine Traineranleitung ist (auch für den Medienwähler). */
|
||||
public function isSelectable(ContentElement $element): bool
|
||||
{
|
||||
return $this->allowed($element);
|
||||
}
|
||||
|
||||
/** Ein Film, der nicht archiviert, nicht gesperrt und keine Traineranleitung ist. */
|
||||
private function allowed(ContentElement $element): bool
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
use App\Domain\Cms\Widgets\RenderContext;
|
||||
use App\Domain\Cms\Widgets\Support\HeadingAccent;
|
||||
use App\Domain\Cms\Widgets\Support\HeroVideo;
|
||||
use App\Domain\Cms\Widgets\Support\ImageRefFields;
|
||||
use App\Domain\Cms\Widgets\Support\PremiumFields;
|
||||
use App\Domain\Cms\Widgets\Support\PublicMedia;
|
||||
@@ -13,6 +14,7 @@
|
||||
use App\Domain\Cms\Widgets\WidgetType;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\ViewField;
|
||||
use Filament\Schemas\Components\Group;
|
||||
|
||||
/**
|
||||
@@ -20,6 +22,11 @@
|
||||
*
|
||||
* Version 1 (Bestand): data {image, alt, body} mit Klartext.
|
||||
* Version 2: data {title, body (formatierter Text), alt}, refs {image}, Varianten Bild links/rechts.
|
||||
* Ohne Versionssprung ergänzt (ältere Revisionen bleiben unverändert darstellbar): Bildanteil (settings.image_share),
|
||||
* Bild ohne Text (Text ist nicht mehr Pflicht, wenn ein Bild gewählt ist) und ein Video (refs.video, ein Film aus dem
|
||||
* Medienmanager): Das freigegebene Video (Trailer, Vorschauclip oder Website-Datei, Regel CardClip) spielt auf dem Bild
|
||||
* beim Überfahren mit der Maus stumm und per Klick oder Schaltfläche mit Ton, wie auf der Medienkarte.
|
||||
*
|
||||
* Version 3: zusätzlich Label, zwei Schaltflächen, Bildfokus in Prozent; Einstellungen Oberfläche, Höhe und
|
||||
* Überschriftenebene. Die Bildseite bleibt die Variante (keine doppelte Einstellung). Die Einstellung
|
||||
* format der Designiteration 1 entfällt; die Bildproportion folgt jetzt der Höhe.
|
||||
@@ -110,10 +117,25 @@ public function optionIcons(): array
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Bildanteil an der Breite im zweispaltigen Stand (ab 900 px Containerbreite): Bild- und Textspalte als Verhältnis.
|
||||
* Ohne Wert gilt die bisherige Verteilung (Text 1,1 : Bild 0,9, je nach Bildseite).
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public const IMAGE_SHARE = [
|
||||
'third' => 'Schmales Bild (ein Drittel Bild, zwei Drittel Text)',
|
||||
'two_fifths' => 'Eher schmales Bild (40 % Bild, 60 % Text)',
|
||||
'half' => 'Gleich breit (je die Hälfte)',
|
||||
'three_fifths' => 'Eher breites Bild (60 % Bild, 40 % Text)',
|
||||
'two_thirds' => 'Breites Bild (zwei Drittel Bild, ein Drittel Text)',
|
||||
];
|
||||
|
||||
public function settings(): array
|
||||
{
|
||||
return [
|
||||
'surface' => ['cream' => 'Creme (Markenfläche)', 'clear' => 'Ohne eigene Fläche', 'navy' => 'Navy (dunkel)'],
|
||||
'image_share' => self::IMAGE_SHARE,
|
||||
'heading_level' => PremiumFields::HEADING_LEVELS,
|
||||
'symbol' => HeadingAccent::symbols(),
|
||||
'symbol_size' => HeadingAccent::SIZE,
|
||||
@@ -124,7 +146,7 @@ public function settings(): array
|
||||
public function settingGroups(): array
|
||||
{
|
||||
return [
|
||||
'Aussehen' => ['surface', 'symbol', 'symbol_size', 'symbol_align'],
|
||||
'Aussehen' => ['surface', 'image_share', 'symbol', 'symbol_size', 'symbol_align'],
|
||||
'Seitenstruktur' => ['heading_level'],
|
||||
];
|
||||
}
|
||||
@@ -133,6 +155,7 @@ public function settingLabels(): array
|
||||
{
|
||||
return [
|
||||
'surface' => ['Hintergrund des Widgets', 'Unabhängig vom Abschnittshintergrund. „Ohne eigene Fläche“ übernimmt den Abschnitt.'],
|
||||
'image_share' => ['Bildanteil', 'Verhältnis von Bild und Text nebeneinander. Gilt erst ab 900 px Breite des Widgets; schmaler steht das Bild über dem Text. Ohne Auswahl bleibt es bei der bisherigen Verteilung (Text etwas breiter als das Bild). Ohne Text füllt das Bild die ganze Breite.'],
|
||||
'symbol' => HeadingAccent::SYMBOL_LABEL,
|
||||
'symbol_size' => HeadingAccent::SIZE_LABEL,
|
||||
'symbol_align' => HeadingAccent::ALIGN_LABEL,
|
||||
@@ -180,13 +203,14 @@ public function dataRules(): array
|
||||
{
|
||||
return [
|
||||
'title' => ['nullable', 'string', 'max:160'],
|
||||
'body' => ['required', 'string', 'max:40000'],
|
||||
// Der Text ist nur Pflicht, solange kein Bild gewählt ist (clean); ein Bild darf allein stehen.
|
||||
'body' => ['nullable', 'string', 'max:40000'],
|
||||
] + PremiumFields::rules();
|
||||
}
|
||||
|
||||
public function refRules(): array
|
||||
{
|
||||
return ImageRefFields::rules();
|
||||
return ImageRefFields::rules() + ['video' => ['nullable']];
|
||||
}
|
||||
|
||||
public function dataFields(): array
|
||||
@@ -196,7 +220,7 @@ public function dataFields(): array
|
||||
TextInput::make('title')->label('Überschrift')->maxLength(160)->live(onBlur: true),
|
||||
RichEditor::make('body')
|
||||
->label('Text')
|
||||
->required()
|
||||
->helperText('Leer lassen, wenn nur das Bild gezeigt werden soll. Ohne Text, Überschrift, Label und Schaltflächen füllt das Bild die ganze Breite.')
|
||||
->live(onBlur: true)
|
||||
->toolbarButtons(RichText::TOOLBAR),
|
||||
PremiumFields::ctaFields(),
|
||||
@@ -207,7 +231,16 @@ public function dataFields(): array
|
||||
|
||||
public function refFields(): array
|
||||
{
|
||||
return ImageRefFields::fields(live: true);
|
||||
return [...ImageRefFields::fields(live: true), $this->videoField()];
|
||||
}
|
||||
|
||||
private function videoField(): ViewField
|
||||
{
|
||||
return ViewField::make('video')
|
||||
->live()
|
||||
->label('Video (optional)')
|
||||
->view('filament.cms.video-feld')
|
||||
->helperText('Ein Film aus dem Medienmanager, über denselben Wähler wie das Bild. Das Bild bleibt stehen; das Video spielt darauf beim Überfahren stumm und per Klick oder Schaltfläche mit Ton, nur wenn ein Trailer, Vorschauclip oder die Website-Datei des Films für die Website freigegeben ist. Die Auswahl gibt nichts frei.');
|
||||
}
|
||||
|
||||
public function editorSchema(): array
|
||||
@@ -234,13 +267,47 @@ public function clean(array $data, array $refs, WidgetErrors $errors): array
|
||||
$data['title'] = filled($data['title'] ?? null) ? trim((string) $data['title']) : null;
|
||||
$data = PremiumFields::clean($data, $errors, $refs['image'] !== null);
|
||||
|
||||
if (RichText::isBlank($data['body'])) {
|
||||
$errors->add('data.body', 'Bitte einen Text eingeben.');
|
||||
$video = app(HeroVideo::class)->clean($refs['video'] ?? null, $errors);
|
||||
$video === null ? $refs = array_diff_key($refs, ['video' => true]) : $refs['video'] = $video;
|
||||
|
||||
if ($video !== null && $refs['image'] === null) {
|
||||
$errors->add('refs.image', 'Bitte auch ein Bild wählen: Es steht, bis das Video startet.');
|
||||
}
|
||||
|
||||
if ($refs['image'] === null && ! self::hasCopy($data)) {
|
||||
$errors->add('data.body', 'Bitte einen Text eingeben oder ein Bild wählen.');
|
||||
}
|
||||
|
||||
return [$data, $refs];
|
||||
}
|
||||
|
||||
/**
|
||||
* Ob neben dem Bild etwas zu lesen ist: Text, Überschrift, Label oder Schaltfläche. Ohne bleibt das Bild allein.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public static function hasCopy(array $data): bool
|
||||
{
|
||||
$body = is_string($data['body'] ?? null) ? RichText::sanitize($data['body']) : '';
|
||||
|
||||
return ! RichText::isBlank($body)
|
||||
|| filled($data['title'] ?? null)
|
||||
|| filled($data['eyebrow'] ?? null)
|
||||
|| PremiumFields::actions($data) !== [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gültiger Bildanteil oder null (bisherige Verteilung).
|
||||
*
|
||||
* @param array<string, mixed> $settings
|
||||
*/
|
||||
public static function imageShare(array $settings): ?string
|
||||
{
|
||||
$share = $settings['image_share'] ?? null;
|
||||
|
||||
return is_string($share) && array_key_exists($share, self::IMAGE_SHARE) ? $share : null;
|
||||
}
|
||||
|
||||
public function resolve(array $widget, RenderContext $context): array
|
||||
{
|
||||
$surface = $widget['settings']['surface'] ?? 'cream';
|
||||
@@ -248,10 +315,23 @@ public function resolve(array $widget, RenderContext $context): array
|
||||
$images = app(WebsiteImage::class);
|
||||
$image = $widget['refs']['image'] ?? null;
|
||||
|
||||
$imageUrl = $images->url($image, $context->preview);
|
||||
$imageAlt = $images->alt($image, $widget['data']['alt'] ?? null);
|
||||
$hasCopy = self::hasCopy($widget['data'] ?? []);
|
||||
$video = app(HeroVideo::class)->resolve($widget['refs']['video'] ?? null, $context->preview);
|
||||
|
||||
// Ohne Bild gibt es nichts, worauf das Video stehen könnte; die Redaktion erfährt es in der Vorschau.
|
||||
if ($imageUrl === null && $video['url'] !== null) {
|
||||
$video = ['url' => null, 'title' => $video['title'], 'notice' => $context->preview ? 'Das Video braucht ein Bild: Es steht, bis das Video startet. Bitte ein Bild wählen.' : null];
|
||||
}
|
||||
|
||||
return [
|
||||
'imageUrl' => $images->url($image, $context->preview),
|
||||
'imageAlt' => $images->alt($image, $widget['data']['alt'] ?? null),
|
||||
'imageUrl' => $imageUrl,
|
||||
'imageAlt' => $imageAlt,
|
||||
'imageNotice' => $context->preview ? $images->previewNotice($image) : null,
|
||||
'video' => $video,
|
||||
'hasCopy' => $hasCopy,
|
||||
'imageShare' => self::imageShare($widget['settings'] ?? []),
|
||||
'body' => RichText::sanitize(is_string($widget['data']['body'] ?? null) ? $widget['data']['body'] : ''),
|
||||
'actions' => PremiumFields::actions($widget['data']),
|
||||
'focus' => PremiumFields::focus($widget['data'], 64, 43),
|
||||
@@ -270,6 +350,16 @@ public function summary(array $widget): string
|
||||
{
|
||||
$title = $widget['data']['title'] ?? null;
|
||||
|
||||
return filled($title) ? (string) $title : RichText::excerpt($widget['data']['body'] ?? '');
|
||||
if (filled($title)) {
|
||||
return (string) $title;
|
||||
}
|
||||
|
||||
$excerpt = RichText::excerpt($widget['data']['body'] ?? '');
|
||||
|
||||
if ($excerpt !== '') {
|
||||
return $excerpt;
|
||||
}
|
||||
|
||||
return filled($widget['data']['alt'] ?? null) ? 'Bild: '.$widget['data']['alt'] : 'Bild';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user