wip: form refactoring
This commit is contained in:
@@ -5,10 +5,10 @@ declare(strict_types=1);
|
||||
namespace App\Form\Service;
|
||||
|
||||
use App\Form\Model\BookingDtoInterface;
|
||||
use App\Form\ParticipantFieldHandler\Condition\FieldConditionInterface;
|
||||
use App\Form\ParticipantFieldHandler\Condition\MutabilityCondition;
|
||||
use App\Form\ParticipantFieldHandler\Condition\ApplicantCondition;
|
||||
use App\Form\ParticipantFieldHandler\Condition\CompositeCondition;
|
||||
use App\Form\ParticipantFieldHandler\Condition\FieldConditionInterface;
|
||||
use App\Form\ParticipantFieldHandler\Condition\MutabilityCondition;
|
||||
|
||||
/**
|
||||
* Field state provider for the booking edit workflow.
|
||||
@@ -21,6 +21,8 @@ use App\Form\ParticipantFieldHandler\Condition\CompositeCondition;
|
||||
*/
|
||||
class EditFieldStateProvider implements FieldStateProviderInterface
|
||||
{
|
||||
use FormTraversalTrait;
|
||||
|
||||
/** @var array<string, array<string, FieldConditionInterface>> */
|
||||
private array $fieldStateConditions = [];
|
||||
|
||||
@@ -109,6 +111,7 @@ class EditFieldStateProvider implements FieldStateProviderInterface
|
||||
foreach ($this->fieldStateConditions[$fieldName] as $condition) {
|
||||
$dependencies = array_merge($dependencies, $condition->getDependentFields());
|
||||
}
|
||||
|
||||
return array_unique($dependencies);
|
||||
}
|
||||
|
||||
@@ -121,6 +124,7 @@ class EditFieldStateProvider implements FieldStateProviderInterface
|
||||
$allStates[$fieldName] = $fieldState;
|
||||
}
|
||||
}
|
||||
|
||||
return $allStates;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service;
|
||||
|
||||
use App\Form\Model\BookingDtoInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
|
||||
/**
|
||||
* Trait providing form tree traversal utilities.
|
||||
*
|
||||
* This trait contains common form navigation logic used across different
|
||||
* form services and types. It centralizes the logic for finding root forms
|
||||
* and extracting booking DTOs from form hierarchies.
|
||||
*/
|
||||
trait FormTraversalTrait
|
||||
{
|
||||
/**
|
||||
* Gets the BookingDtoInterface from the root of the form tree.
|
||||
*
|
||||
* This helper method traverses up the form tree to find the root form
|
||||
* and extracts the BookingDtoInterface data. This is shared logic used
|
||||
* by both create and edit participant forms.
|
||||
*
|
||||
* @param FormInterface $form The form to start traversing from
|
||||
*
|
||||
* @return BookingDtoInterface|null The booking DTO or null if not found
|
||||
*/
|
||||
public function getBookingDtoFromForm(FormInterface $form): ?BookingDtoInterface
|
||||
{
|
||||
// Traverse up the form tree to get the root form's data
|
||||
$rootForm = $form;
|
||||
while ($rootForm->getParent()) {
|
||||
$rootForm = $rootForm->getParent();
|
||||
}
|
||||
|
||||
$data = $rootForm->getData();
|
||||
|
||||
return $data instanceof BookingDtoInterface ? $data : null;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service;
|
||||
|
||||
use App\Form\Model\BookingCreateDto;
|
||||
use App\Form\Model\BookingDtoInterface;
|
||||
use App\Form\ParticipantFieldHandler\Condition\FieldConditionInterface;
|
||||
|
||||
@@ -26,6 +27,8 @@ use App\Form\ParticipantFieldHandler\Condition\FieldConditionInterface;
|
||||
*/
|
||||
class ParticipantFieldOptionsProvider implements FieldStateProviderInterface
|
||||
{
|
||||
use FormTraversalTrait;
|
||||
|
||||
/** @var array<string, callable> Field option providers indexed by field name */
|
||||
private array $fieldOptionProviders = [];
|
||||
|
||||
@@ -120,7 +123,7 @@ class ParticipantFieldOptionsProvider implements FieldStateProviderInterface
|
||||
*/
|
||||
private function registerFieldOptionProviders(): void
|
||||
{
|
||||
// Room assignment field provider
|
||||
// Room assignment field provider (only available for create workflow)
|
||||
$this->fieldOptionProviders['assignedRoomId'] = fn (BookingDtoInterface $bookingDto, int $participantIndex) => [
|
||||
'label' => 'Zimmer',
|
||||
'placeholder' => 'Bitte wählen',
|
||||
@@ -128,11 +131,13 @@ class ParticipantFieldOptionsProvider implements FieldStateProviderInterface
|
||||
// - Shows only available rooms for this participant
|
||||
// - Excludes rooms already assigned to other participants
|
||||
// - Respects room capacity and booking constraints
|
||||
'choice_loader' => $this->roomChoiceLoaderFactory->create(
|
||||
$bookingDto->participants,
|
||||
$bookingDto->getSelectedRooms(),
|
||||
$participantIndex
|
||||
),
|
||||
'choice_loader' => $bookingDto instanceof BookingCreateDto
|
||||
? $this->roomChoiceLoaderFactory->create(
|
||||
$bookingDto->participants,
|
||||
$bookingDto->getSelectedRooms(),
|
||||
$participantIndex
|
||||
)
|
||||
: null,
|
||||
];
|
||||
|
||||
// Future field providers would be added here, for example:
|
||||
|
||||
Reference in New Issue
Block a user