Store the birthday as a plain TT.MM.JJJJ text field in the backend
The field was declared as a Contao date field, so DC_Table parsed the stored W&K format with the website's date format and threw "Invalid date" when opening a booking. A save callback now normalises and validates the value the same way the frontend form does. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
cabe5506e6
commit
6e75ad31ea
3 files changed
+36
-1
No files matched your search
@@ -188,7 +188,8 @@ $GLOBALS['TL_DCA']['tl_wk_booking'] = [
|
||||
'birthday' => [
|
||||
'exclude' => true,
|
||||
'inputType' => 'text',
|
||||
'eval' => ['rgxp' => 'date', 'maxlength' => 10, 'tl_class' => 'w50'],
|
||||
// Wird wie im Formular als TT.MM.JJJJ gespeichert (W&K-Format), siehe BirthdayListener
|
||||
'eval' => ['maxlength' => 10, 'placeholder' => 'TT.MM.JJJJ', 'tl_class' => 'w50'],
|
||||
'sql' => ['type' => 'string', 'length' => 10, 'default' => ''],
|
||||
],
|
||||
'teacherPosition' => [
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mummert\ContaoWkSyncBundle\EventListener\DataContainer;
|
||||
|
||||
use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback;
|
||||
use Mummert\ContaoWkSyncBundle\Booking\BookingCreator;
|
||||
|
||||
/**
|
||||
* Der Geburtstag wird wie im Anmeldeformular als TT.MM.JJJJ gespeichert (W&K-Format), unabhängig vom
|
||||
* Datumsformat der Website. Ein Contao-Datumsfeld (rgxp=date) würde den gespeicherten Wert mit dem
|
||||
* Systemformat parsen und im Backend einen Fehler werfen.
|
||||
*/
|
||||
#[AsCallback(table: 'tl_wk_booking', target: 'fields.birthday.save')]
|
||||
class BirthdayListener
|
||||
{
|
||||
public function __invoke(mixed $value): string
|
||||
{
|
||||
$value = trim((string) $value);
|
||||
|
||||
if ('' === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$normalized = BookingCreator::normalizeDate($value);
|
||||
|
||||
if (!preg_match('/^(\d{2})\.(\d{2})\.(\d{4})$/', $normalized, $m) || !checkdate((int) $m[2], (int) $m[1], (int) $m[3])) {
|
||||
throw new \RuntimeException(\sprintf($GLOBALS['TL_LANG']['ERR']['date'] ?? 'Ungültiges Datum "%s"', $value));
|
||||
}
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
}
|
||||
File renamed without changes.
Reference in new issue
Block a user