Custom field validator comparing original and new values In my validator, I need to compare the new field value, that was submitted by the user, with the old value. How can I get the original value?
So far, I have this:
class CompareNewOldValuesValidator extends ConstraintValidator {

  public function validate($item, Constraint $constraint) {

    if (empty($item-&gt;getValue())) {
      return;
    }
    $value_new = $item-&gt;getValue()[0]['value'];

    /** @var ContentEntityInterface $entity */
    $entity = $item-&gt;getEntity();
    if (!$entity-&gt;isNew()) {
      $value_original = '???';
    }
  }
}    

I need to get the field value that was filled in the form before the user changed it, no matter if it is the active version or a draft or an old revision.
Normally the original entity is stored in the entity object before the user input is applied. If not, you can get it via the loaded revision id, which is preserved when an entity is loaded to keep it save from changes:
if (isset($entity-&gt;original)) {
  $original = $entity-&gt;original;
}
else {
  $original = \Drupal::entityTypeManager()
    -&gt;getStorage($entity-&gt;getEntityTypeId())
    -&gt;loadRevision($entity-&gt;getLoadedRevisionId());
}

$value_original = $original-&gt;{$item-&gt;getFieldDefinition()-&gt;getName()}-&gt;value;