first delivery

This commit is contained in:
Alexandre Gain committed 2026-11-07 19:31:49 +01:00
1 parent 793fbc0c91
commit f6684f3b2e
65 files changed
+5828

No files matched your search

@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Validator\Constraints;
use MauticPlugin\PlanBundle\Entity\Task;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
class ValidTaskParentValidator extends ConstraintValidator
{
public function validate(mixed $value, Constraint $constraint): void
{
if (!$constraint instanceof ValidTaskParent) {
throw new UnexpectedTypeException($constraint, ValidTaskParent::class);
}
if (null === $value) {
return;
}
if (!$value instanceof Task) {
throw new UnexpectedValueException($value, Task::class);
}
$parent = $value->getParent();
if (null === $parent) {
return;
}
// The parent's ancestors include the task itself: the task is its own parent or a sub-task's child.
if ($parent->hasAncestorOrSelf($value)) {
$this->context->buildViolation($constraint->loopMessage)
->atPath('parent')
->addViolation();
return;
}
$plan = $value->getPlan();
$parentPlan = $parent->getPlan();
if (null !== $plan && null !== $parentPlan && $plan->getId() !== $parentPlan->getId()) {
$this->context->buildViolation($constraint->otherPlanMessage)
->atPath('parent')
->addViolation();
}
}
}