wip: modernized edit flow

This commit is contained in:
Björn Fromme
2026-03-16 11:59:10 +01:00
parent 0d073a36a3
commit 28831a3b06
75 changed files with 1662 additions and 747 deletions
@@ -7,7 +7,7 @@ namespace App\Form\Service;
use App\BusProNet\Model\Insurance;
use App\BusProNet\Model\Pickup;
use App\BusProNet\Model\Service;
use App\Form\Model\BookingDtoInterface;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Form\Service\Contract\ParticipantFieldHandlerInterface;
@@ -75,12 +75,14 @@ class ParticipantFieldHandlerRegistry
* automatically cleared.
*
* @param array<string, mixed> $submittedData The submitted form data containing participants array
* @param BookingDtoInterface $bookingDto The booking DTO to update with processed field values
* @param BookingDto $bookingDto The booking DTO to update with processed field values
*
* @return array<string, mixed> The synchronized submitted data reflecting DTO changes
*/
public function processFieldsAndSync(array $submittedData, BookingDtoInterface $bookingDto): array
public function processFieldsAndSync(array $submittedData, BookingDto $bookingDto): array
{
error_log(sprintf('[ProcessFieldsAndSync] Mode: %s', $bookingDto->getMode()));
// Process all field handlers to clean the DTO
$this->processFields($submittedData, $bookingDto);
@@ -105,9 +107,9 @@ class ParticipantFieldHandlerRegistry
* family detection which needs all participants' ages to be processed first).
*
* @param array<string, mixed> $submittedData The submitted form data containing participants array
* @param BookingDtoInterface $bookingDto The booking DTO to update with processed field values (create or edit)
* @param BookingDto $bookingDto The booking DTO to update with processed field values (create or edit)
*/
public function processFields(array $submittedData, BookingDtoInterface $bookingDto): void
public function processFields(array $submittedData, BookingDto $bookingDto): void
{
// Early return if no participant data exists in submission
if (false === isset($submittedData['participants']) || false === is_array($submittedData['participants'])) {
@@ -245,15 +247,18 @@ class ParticipantFieldHandlerRegistry
* that the form continues processing with cleaned data rather than the original
* submitted data that may contain invalid selections.
*
* In edit mode, this also adds the applicant's personal data to the submitted data
* for participant 0, ensuring those fields are bound to the DTO by handleRequest.
*
* The synchronization is generic and works with any field handlers by examining
* the current DTO state and updating the corresponding submitted data fields.
*
* @param array<string, mixed> $submittedData The original submitted form data
* @param BookingDtoInterface $bookingDto The DTO with cleaned data from field handlers
* @param BookingDto $bookingDto The DTO with cleaned data from field handlers
*
* @return array<string, mixed> Updated submitted data reflecting DTO state
*/
private function syncSubmittedDataWithDto(array $submittedData, BookingDtoInterface $bookingDto): array
private function syncSubmittedDataWithDto(array $submittedData, BookingDto $bookingDto): array
{
// Ensure participants array exists in submitted data
if (false === isset($submittedData['participants']) || false === is_array($submittedData['participants'])) {
@@ -272,7 +277,7 @@ class ParticipantFieldHandlerRegistry
}
// Update participant data to match cleaned DTO state
$submittedData['participants'][$index] = $this->syncParticipantData($participantData, $participant);
$submittedData['participants'][$index] = $this->syncParticipantData($participantData, $participant, $index, $bookingDto);
}
return $submittedData;
@@ -285,13 +290,20 @@ class ParticipantFieldHandlerRegistry
* any changes made by field handlers. It automatically detects which fields have
* been processed by checking against registered handlers.
*
* In edit mode for participant 0 (applicant), this also adds the personal data fields
* that were patched from the applicant, ensuring they're bound to the DTO.
*
* @param array<string, mixed> $participantData The submitted participant data
* @param ParticipantDto $participant The cleaned participant DTO
* @param int $index The participant index
* @param BookingDto $bookingDto The booking DTO for mode detection
*
* @return array<string, mixed> Updated participant data with synchronized field values
*/
private function syncParticipantData(array $participantData, ParticipantDto $participant): array
private function syncParticipantData(array $participantData, ParticipantDto $participant, int $index, BookingDto $bookingDto): array
{
error_log(sprintf('[Sync] Participant %d fields in submission: %s', $participant->index ?? -1, implode(', ', array_keys($participantData))));
// Sync fields for all registered handlers
foreach ($this->handlers as $fieldName => $handler) {
// Only sync fields that were in the original submission
@@ -299,6 +311,7 @@ class ParticipantFieldHandlerRegistry
if (property_exists($participant, $fieldName) && array_key_exists($fieldName, $participantData)) {
$dtoValue = $participant->{$fieldName};
$participantData[$fieldName] = $this->convertDtoValueToSubmittedFormat($dtoValue);
error_log(sprintf('[Sync] Participant %d: synced %s', $participant->index ?? -1, $fieldName));
}
}
@@ -362,6 +375,17 @@ class ParticipantFieldHandlerRegistry
return $value->id;
}
// Handle Address objects -> convert to array of properties
if ($value instanceof \App\BusProNet\Model\Address) {
return [
'street' => $value->street,
'postCode' => $value->postCode,
'city' => $value->city,
'district' => $value->district,
'country' => $value->country,
];
}
// Handle DateTimeInterface -> convert to string format
if ($value instanceof \DateTimeInterface) {
return $value->format('Y-m-d');