3 namespace Drupal\Core\Entity\Plugin\Validation\Constraint;
5 use Symfony\Component\Validator\Constraint;
6 use Symfony\Component\Validator\ConstraintValidator;
9 * Validates the EntityChanged constraint.
11 class EntityChangedConstraintValidator extends ConstraintValidator {
16 public function validate($entity, Constraint $constraint) {
18 /** @var \Drupal\Core\Entity\EntityInterface $entity */
19 if (!$entity->isNew()) {
20 $saved_entity = \Drupal::entityManager()->getStorage($entity->getEntityTypeId())->loadUnchanged($entity->id());
21 // A change to any other translation must add a violation to the current
22 // translation because there might be untranslatable shared fields.
23 if ($saved_entity && $saved_entity->getChangedTimeAcrossTranslations() > $entity->getChangedTimeAcrossTranslations()) {
24 $this->context->addViolation($constraint->message);