Newer
Older
Angie Byron
committed
<?php
/**
* @file
Angie Byron
committed
* Contains \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityChangedConstraintValidator.
Angie Byron
committed
*/
Angie Byron
committed
namespace Drupal\Core\Entity\Plugin\Validation\Constraint;
Angie Byron
committed
use Drupal\Core\Entity\EntityChangedInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* Validates the EntityChanged constraint.
*/
class EntityChangedConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint) {
if (isset($value)) {
/** @var $entity \Drupal\Core\Entity\EntityInterface */
$entity = $this->context->getMetadata()->getTypedData()->getEntity();
Angie Byron
committed
if (!$entity->isNew()) {
catch
committed
$saved_entity = \Drupal::entityManager()->getStorage($entity->getEntityTypeId())->loadUnchanged($entity->id());
Angie Byron
committed
if ($saved_entity && ($saved_entity instanceof EntityChangedInterface) && ($saved_entity->getChangedTime() > $value)) {
$this->context->addViolation($constraint->message);
}
}
}
}
}