Feste Profilfelder in Formularen, Geburtstage, anpassbare Startseite
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m21s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m40s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m34s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 3m8s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 3m6s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m43s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m47s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m1s

- Formulare: Felder fest aus dem Profil (nicht änderbar, Server setzt den
  Profilwert ein), Hinweis bei fehlender Profilangabe
- Geburtstage (optionales Plugin, standardmäßig aus): Tag und Monat freiwillig
  im Profil, Kachel, Liste /geburtstage, Pagebuilder-Block, Glückwunsch am
  eigenen Geburtstag; Sichtbarkeit alle/Abteilung/Standort
- Startseite: Kacheln je Bereich sortieren und ausblenden; eigene Kacheln
  (Bild mit Link, Text, Hinweis) mit Zeitraum und Zielgruppe
- Kern: optionale mitgelieferte Plugins, Startseitenbereich „top“,
  Profilabschnitte für Plugins, Kachel-Bezeichnungen

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 09:51:19 +00:00
parent 435960725d
commit ee8dde93c0
262 changed files with 2385 additions and 692 deletions

View file

@ -1,7 +1,7 @@
<script setup>
import { computed } from 'vue';
import { useForm, usePage } from '@inertiajs/vue3';
import { CircleCheck, EyeOff, LoaderCircle, Paperclip, Send, X } from '@lucide/vue';
import { CircleCheck, EyeOff, LoaderCircle, Lock, Paperclip, Send, X } from '@lucide/vue';
import { toast } from 'vue-sonner';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
@ -176,6 +176,12 @@ const fieldId = (field) => `f${props.form.id}-${field.key}`;
</label>
</div>
<div v-else-if="field.locked" class="flex h-9 items-center gap-2 rounded-md border border-input bg-muted/60 px-3 text-sm" :aria-describedby="`${fieldId(field)}-locked`">
<Lock class="size-3.5 shrink-0 text-muted-foreground" />
<span v-if="data.answers[field.key]" :id="fieldId(field)" class="truncate">{{ data.answers[field.key] }}</span>
<span v-else class="text-muted-foreground italic">{{ preview ? 'wird aus dem Profil übernommen' : 'nicht im Profil hinterlegt' }}</span>
</div>
<Input
v-else
:id="fieldId(field)"
@ -189,7 +195,11 @@ const fieldId = (field) => `f${props.form.id}-${field.key}`;
/>
</template>
<p v-if="error(field)" class="text-[13px] text-destructive">{{ error(field) }}</p>
<p v-if="error(field)" class="text-[13px] text-destructive">
{{ error(field) }}
<a v-if="field.locked" href="/profil/bearbeiten" class="font-medium underline">Profil öffnen</a>
</p>
<p v-else-if="field.locked" :id="`${fieldId(field)}-locked`" class="text-[13px] text-muted-foreground">Aus Ihrem Profil – nicht änderbar.</p>
<p v-else-if="field.help" class="text-[13px] text-muted-foreground">
{{ field.help }}<template v-if="field.type === 'file' && field.max_size"> (höchstens {{ field.max_size }} MB)</template>
</p>

View file

@ -1,6 +1,6 @@
<script setup>
import { computed, inject } from 'vue';
import { Asterisk, Calendar, ChevronDown, Copy, GitBranch, GripVertical, Paperclip, Plus, Trash2, X } from '@lucide/vue';
import { Asterisk, Calendar, ChevronDown, Copy, GitBranch, GripVertical, Lock, Paperclip, Plus, Trash2, X } from '@lucide/vue';
import { fieldTypes, layoutTypes, operators, optionTypes } from '../../lib/fields';
/**
@ -95,6 +95,9 @@ const fake = 'flex h-9 w-full items-center rounded-md border border-input bg-car
<button type="button" class="grid size-6 place-items-center rounded text-destructive hover:bg-destructive/10" title="Entfernen" @click="builder.remove(field._id)"><Trash2 class="size-3.5" /></button>
</div>
<p v-if="d.prefill && !d.locked && !isLayout" class="mb-1.5 mr-1 inline-flex items-center gap-1 rounded bg-muted px-1.5 py-0.5 text-[11px] text-muted-foreground">
Vorbelegt: {{ builder.prefillOptions.find((o) => o.value === d.prefill)?.label ?? d.prefill }}
</p>
<p v-if="conditionText" class="mb-1.5 inline-flex items-center gap-1 rounded bg-amber-100 px-1.5 py-0.5 text-[11px] text-amber-800 dark:bg-amber-900/50 dark:text-amber-200">
<GitBranch class="size-3" /> Nur wenn {{ conditionText }}
</p>
@ -156,6 +159,10 @@ const fake = 'flex h-9 w-full items-center rounded-md border border-input bg-car
<div v-else-if="field.type === 'date'" :class="[fake, 'justify-between']">TT.MM.JJJJ <Calendar class="size-4" /></div>
<div v-else-if="d.locked && d.prefill" class="flex h-9 items-center gap-2 rounded-md border border-input bg-muted/60 px-3 text-sm text-muted-foreground">
<Lock class="size-3.5" /> Aus dem Profil: {{ builder.prefillOptions.find((o) => o.value === d.prefill)?.label ?? d.prefill }} – nicht änderbar
</div>
<div v-else class="rounded-md border border-input bg-card shadow-xs">
<input v-model="d.placeholder" class="h-9 w-full bg-transparent px-3 text-sm outline-none placeholder:text-muted-foreground/50" :placeholder="field.type === 'text' ? 'Platzhalter (optional)' : ''" :disabled="field.type !== 'text'" aria-label="Platzhalter" />
</div>

View file

@ -121,9 +121,20 @@ const maxSize = computed(number('max_size'));
<label v-if="['text', 'email', 'phone'].includes(field.type)" class="grid gap-1.5">
<span class="text-[13px] font-medium">Vorbelegen mit</span>
<NativeSelect :model-value="d.prefill ?? null" :options="builder.prefillOptions" placeholder="– nicht vorbelegen –" @update:model-value="(v) => (v ? (d.prefill = v) : delete d.prefill)" />
<span class="text-xs text-muted-foreground">Aus dem Profil der ausfüllenden Person; änderbar.</span>
<NativeSelect :model-value="d.prefill ?? null" :options="builder.prefillOptions" placeholder="– nicht vorbelegen –" @update:model-value="(v) => (v ? (d.prefill = v) : (delete d.prefill, delete d.locked))" />
</label>
<div v-if="['text', 'email', 'phone'].includes(field.type) && d.prefill" class="grid gap-1.5 rounded-md border p-3">
<label class="flex items-center justify-between gap-3 text-[13px] font-medium">
Nicht änderbar
<Switch :model-value="!!d.locked" @update:model-value="(v) => (v ? (d.locked = true) : delete d.locked)" />
</label>
<span class="text-xs text-muted-foreground">
{{ d.locked
? 'Das Feld zeigt den Wert aus dem Profil und kann nicht geändert werden. Beim Absenden wird immer der Profilwert gespeichert.'
: 'Das Feld ist mit dem Profilwert vorausgefüllt, kann aber geändert werden.' }}
</span>
<span v-if="d.locked && builder.anonymous" class="text-xs text-amber-700 dark:text-amber-300">Achtung: Das Formular ist anonym – diese Profilangabe wird trotzdem mit der Einsendung gespeichert.</span>
</div>
<div v-if="['text', 'textarea', 'number', 'checkboxes'].includes(field.type)" class="grid grid-cols-2 gap-3">
<label v-if="['number', 'checkboxes'].includes(field.type)" class="grid gap-1.5">

View file

@ -97,6 +97,7 @@ export function toFrontend(fields) {
multiple: !!data.multiple,
accept: accept[data.accept ?? 'any'] || undefined,
max_size: data.max_size,
locked: !!(data.locked && data.prefill && ['text', 'email', 'phone'].includes(type)),
condition: data.condition_field ? { field: data.condition_field, operator: data.condition_operator ?? 'equals', value: String(data.condition_value ?? '') } : null,
}));
}

View file

@ -87,6 +87,7 @@ provide('forms:builder', {
},
types: props.types,
prefillOptions: props.prefillOptions,
anonymous: props.form.anonymous,
selectedId,
errorIndex,
select,

View file

@ -116,6 +116,7 @@ class FormFields
'multiple' => (bool) ($d['multiple'] ?? false),
'accept' => isset($d['accept']) ? implode(',', array_map(fn ($ext) => '.'.$ext, self::FILE_TYPES[$d['accept']] ?? self::FILE_TYPES['any'])) : null,
'max_size' => $d['max_size'] ?? null,
'locked' => self::isLocked($field),
'condition' => filled($d['condition_field'] ?? null) ? [
'field' => $d['condition_field'],
'operator' => $d['condition_operator'] ?? 'equals',
@ -149,6 +150,38 @@ class FormFields
return $values;
}
/**
* Feld fest aus dem Profil: nicht änderbar, beim Absenden setzt der Server den Profilwert ein.
*
* @param array{type: string, data: array<string, mixed>} $field
*/
public static function isLocked(array $field): bool
{
return in_array($field['type'], ['text', 'email', 'phone'], true)
&& filled($field['data']['prefill'] ?? null)
&& (bool) ($field['data']['locked'] ?? false);
}
/**
* Eingaben für feste Profilfelder durch die Werte aus dem Profil ersetzen –
* unabhängig davon, was der Browser schickt.
*
* @param array<string, mixed> $answers
* @return array<string, mixed>
*/
public static function applyLocked(Form $form, User $user, array $answers): array
{
$profile = self::prefill($form, $user);
foreach ($form->fields ?? [] as $field) {
if (self::isLocked($field)) {
$answers[$field['data']['key']] = $profile[$field['data']['key']] ?? '';
}
}
return $answers;
}
/**
* @return array<string, string>
*/
@ -231,6 +264,12 @@ class FormFields
$messages[$name.'.accepted'] = 'Bitte bestätigen.';
}
if (self::isLocked($field)) {
$messages[$name.'.required'] = 'Diese Angabe fehlt in Ihrem Profil. Bitte ergänzen Sie sie dort (Profil bearbeiten) oder wenden Sie sich an die Personalverwaltung.';
// Profilwerte werden nicht wie Eingaben geprüft (z. B. Telefonformat).
$rules[$name] = [$required ? 'required' : 'nullable', 'string', 'max:500'];
}
if ($field['type'] === 'checkboxes') {
$rules[$name.'.*'] = ['string', Rule::in($options)];
}

View file

@ -33,6 +33,7 @@ class FormBuilderController extends Controller
'fields' => $form->fields ?? [],
'url' => $form->url(),
'submissions' => $form->submissions()->count(),
'anonymous' => $form->isAnonymous(),
],
'types' => FormFields::TYPES,
'prefillOptions' => collect(FormFields::prefillOptions())->map(fn ($label, $value) => ['value' => $value, 'label' => $label])->values(),
@ -92,9 +93,9 @@ class FormBuilderController extends Controller
{
$allowed = ['label', 'key', 'required', 'help', 'width', 'condition_field', 'condition_operator', 'condition_value'];
$allowed = [...$allowed, ...match ($type) {
'text' => ['placeholder', 'max', 'prefill'],
'text' => ['placeholder', 'max', 'prefill', 'locked'],
'textarea' => ['rows', 'max'],
'email', 'phone' => ['prefill'],
'email', 'phone' => ['prefill', 'locked'],
'number' => ['min', 'max'],
'select', 'radio' => ['options'],
'checkboxes' => ['options', 'min', 'max'],
@ -109,7 +110,7 @@ class FormBuilderController extends Controller
$clean['options'] = array_values(array_unique(array_filter(array_map(fn ($o) => trim((string) $o), $clean['options']), 'strlen')));
}
foreach (['required', 'multiple'] as $flag) {
foreach (['required', 'multiple', 'locked'] as $flag) {
if (isset($clean[$flag])) {
$clean[$flag] = (bool) $clean[$flag];
}
@ -133,6 +134,10 @@ class FormBuilderController extends Controller
unset($clean['prefill']);
}
if (empty($clean['prefill']) || empty($clean['locked'])) {
unset($clean['locked']);
}
if (isset($clean['condition_operator']) && ! in_array($clean['condition_operator'], ['equals', 'not_equals', 'contains', 'filled', 'empty'], true)) {
$clean['condition_operator'] = 'equals';
}

View file

@ -62,6 +62,8 @@ class FormController extends Controller
$answers[$key] = is_array($files) ? $files : [$files];
}
$answers = FormFields::applyLocked($form, $user, $answers);
[$rules, $attributes, $messages] = FormFields::rules($form, $answers);
$validated = Validator::make(['answers' => $answers], $rules, $messages, $attributes)->validate();