b1fee2a29452bf2c290b01053b60aac3f58851e1
[yaffs-website] / web / core / lib / Drupal / Core / Entity / Plugin / Validation / Constraint / EntityChangedConstraintValidator.php
1 <?php
2
3 namespace Drupal\Core\Entity\Plugin\Validation\Constraint;
4
5 use Symfony\Component\Validator\Constraint;
6 use Symfony\Component\Validator\ConstraintValidator;
7
8 /**
9  * Validates the EntityChanged constraint.
10  */
11 class EntityChangedConstraintValidator extends ConstraintValidator {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function validate($entity, Constraint $constraint) {
17     if (isset($entity)) {
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);
25         }
26       }
27     }
28   }
29
30 }