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->getValue())) {
return;
}
$value_new = $item->getValue()[0]['value'];
/** @var ContentEntityInterface $entity */
$entity = $item->getEntity();
if (!$entity->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.