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
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:
parent
435960725d
commit
ee8dde93c0
262 changed files with 2385 additions and 692 deletions
|
|
@ -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)];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue