fix: don't require email address from participants under 16

This commit is contained in:
fromme committed 2026-09-01 15:15:58 +02:00
1 parent 98e0cfcf6f
commit f595183c05
11 files changed
+566 -36

No files matched your search

@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace App\Form\Service\Condition;
use App\Form\Model\BookingDto;
use App\Form\Service\Contract\FieldConditionInterface;
/**
* Condition that checks whether the booking belongs to an internal agency.
*
* Internal agency bookings are made by staff on behalf of a customer, so they are exempt
* from several rules that protect customer-entered data: personal data stays editable and
* fields that are mandatory for customers may be left blank.
*
* This is the plain flag on its own. FirstParticipantReadOnlyCondition and
* PersonalDataMutabilityCondition also consult it, but combine it with further criteria.
*/
class InternalAgencyBookingCondition implements FieldConditionInterface
{
/**
* Evaluates whether the booking is an internal agency booking.
*
* @param BookingDto $bookingDto The current booking data (create or edit)
* @param int $participantIndex The index of the participant being evaluated (unused)
* @param array<string, mixed> $formData Current form data (unused)
*
* @return bool True if the booking was made by an internal agency
*/
public function evaluate(BookingDto $bookingDto, int $participantIndex, array $formData): bool
{
return $bookingDto->isInternalAgencyBooking();
}
/**
* The agency code is a property of the booking, not of any form field.
*
* @return string[] Always empty
*/
public function getDependentFields(): array
{
return [];
}
public function getDescription(): string
{
return 'Checks if the booking is an internal agency booking';
}
}
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace App\Form\Service\Condition;
use App\Form\Model\BookingDto;
use App\Form\Service\Contract\FieldConditionInterface;
/**
* Condition that mirrors ParticipantDto::requiresOwnEmail() into the field state layer.
*
* It deliberately holds no logic of its own. The rule for who needs an email address is
* enforced by the Assert\When on ParticipantDto::$email; this condition exists so the
* mandatory marker rendered next to the field is derived from that same method rather than
* from a second, independently maintained composition of age and applicant conditions.
*/
class RequiresOwnEmailCondition implements FieldConditionInterface
{
/**
* Evaluates whether the participant has to supply an email address of their own.
*
* @param BookingDto $bookingDto The current booking data (create or edit)
* @param int $participantIndex The index of the participant being evaluated
* @param array<string, mixed> $formData Current form data (unused)
*
* @return bool True if the participant needs their own email address
*/
public function evaluate(BookingDto $bookingDto, int $participantIndex, array $formData): bool
{
$participant = $bookingDto->getParticipant($participantIndex);
// A participant that does not exist yet is treated as needing an address, matching the
// "unknown counts as an adult" stance of ParticipantDto::isChild().
return null === $participant || $participant->requiresOwnEmail();
}
/**
* The rule reads the date of birth, so the state has to be recalculated when it changes.
*
* @return string[] Array containing 'dateOfBirth'
*/
public function getDependentFields(): array
{
return ['dateOfBirth'];
}
public function getDescription(): string
{
return 'Checks if the participant needs an email address of their own';
}
}