Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could write a custom DateRangeValidator.</p> <pre><code>class DateRange extends Constraint { public $message = "daterange.violation.crossing"; public $emptyStartDate = "daterange.violation.startDate"; public $emptyEndDate = "daterange.violation.endDate"; public $hasEndDate = true; public function getTargets() { return self::CLASS_CONSTRAINT; } public function validatedBy() { return 'daterange_validator'; } } class DateRangeValidator extends ConstraintValidator { public function isValid($entity, Constraint $constraint) { $hasEndDate = true; if ($constraint-&gt;hasEndDate !== null) { $hasEndDate = $constraint-&gt;hasEndDate; } if ($entity-&gt;getStartDate() !== null) { if ($hasEndDate) { if ($entity-&gt;getEndDate() !== null) { if ($entity-&gt;getStartDate() &gt; $entity-&gt;getEndDate()) { $this-&gt;setMessage($constraint-&gt;message); return false; } return true; } else { $this-&gt;setMessage($constraint-&gt;emptyEndDate); return false; } } else { if ($entity-&gt;getEndDate() !== null) { if ($entity-&gt;getStartDate() &gt; $entity-&gt;getEndDate()) { $this-&gt;setMessage($constraint-&gt;message); return false; } } return true; } } else { $this-&gt;setMessage($constraint-&gt;emptyStartDate); return false; } } </code></pre> <p>register it as a service:</p> <pre><code>parameters: register.daterange.validator.class: XXX\FormExtensionsBundle\Validator\Constraints\DateRangeValidator services: daterange.validator: class: %register.daterange.validator.class% tags: - { name: validator.constraint_validator, alias: daterange_validator } </code></pre> <p>And use it in your Entity:</p> <pre><code>use XXX\FormExtensionsBundle\Validator\Constraints as FormAssert; /** * * @FormAssert\DateRange() */ class Contact extends Entity { private $startDate; private $endDate; } </code></pre> <p>Eventhough it seems a bit much for a simple thing like that, but experience shows, that one needs a date range validator more often than just once.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload