feat: conditionally render room assignment field in participant edit form
This commit is contained in:
1 parent
b872f2a5db
commit
f230b36382
4 files changed
+70
-21
No files matched your search
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service\Condition;
|
||||
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\Contract\FieldConditionInterface;
|
||||
|
||||
/**
|
||||
* Condition that evaluates based on the booking workflow mode.
|
||||
*
|
||||
* Used to apply field states that should only be active in a specific mode
|
||||
* (create or edit), such as making room assignments readonly in edit mode.
|
||||
*/
|
||||
class BookingModeCondition implements FieldConditionInterface
|
||||
{
|
||||
/**
|
||||
* @param string $mode The mode to check against (BookingDto::MODE_CREATE or BookingDto::MODE_EDIT)
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly string $mode,
|
||||
) {
|
||||
if (BookingDto::MODE_CREATE !== $mode && BookingDto::MODE_EDIT !== $mode) {
|
||||
throw new \InvalidArgumentException(sprintf('Invalid mode "%s". Must be one of: %s, %s', $mode, BookingDto::MODE_CREATE, BookingDto::MODE_EDIT));
|
||||
}
|
||||
}
|
||||
|
||||
public function evaluate(BookingDto $bookingDto, int $participantIndex, array $formData): bool
|
||||
{
|
||||
return $this->mode === $bookingDto->getMode();
|
||||
}
|
||||
|
||||
public function getDependentFields(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return sprintf('Returns true when booking is in %s mode', $this->mode);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user