validation attempt with assert\callback: still doesn't work

This commit is contained in:
2021-12-02 15:31:08 +01:00
parent acacef936c
commit c527b1b3cf
2 changed files with 28 additions and 7 deletions

View File

@@ -49,10 +49,6 @@ use UnexpectedValueException;
* "accompanying_period": AccompanyingPeriod::class
* })
* @Assert\GroupSequenceProvider
* @Assert\Expression(
* "this.isConfidential && this.getUser && this.getStep === 'CONFIRMED'",
* message="If the accompanying course is confirmed and confidential, a referrer must remain assigned."
* )
*/
class AccompanyingPeriod implements
TrackCreationInterface,
@@ -860,7 +856,7 @@ class AccompanyingPeriod implements
}
/**
* Validation function.
* Validation functions.
*/
public function isDateConsistent(ExecutionContextInterface $context)
{
@@ -875,6 +871,21 @@ class AccompanyingPeriod implements
}
}
/**
* @Assert\Callback
*/
public function canUserBeNull(ExecutionContextInterface $context)
{
if ($this->getStep() === self::STEP_CONFIRMED && $this->isConfidential() === true)
{
if (!$this->getUser()) {
$context->buildViolation('User cannot be null for an accompanying period that is confirmed and confidential')
->atPath('user')
->addViolation();
}
}
}
public function isEmergency(): bool
{
return $this->emergency;