public function EntityChangedConstraintValidator::validate in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityChangedConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityChangedConstraintValidator::validate()
Checks if the passed value is valid.
Parameters
mixed $value The value that should be validated:
Constraint $constraint The constraint for the validation:
Overrides ConstraintValidatorInterface::validate
File
- core/
lib/ Drupal/ Core/ Entity/ Plugin/ Validation/ Constraint/ EntityChangedConstraintValidator.php, line 21 - Contains \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityChangedConstraintValidator.
Class
- EntityChangedConstraintValidator
- Validates the EntityChanged constraint.
Namespace
Drupal\Core\Entity\Plugin\Validation\ConstraintCode
public function validate($entity, Constraint $constraint) {
if (isset($entity)) {
/** @var \Drupal\Core\Entity\EntityInterface $entity */
if (!$entity
->isNew()) {
$saved_entity = \Drupal::entityManager()
->getStorage($entity
->getEntityTypeId())
->loadUnchanged($entity
->id());
// A change to any other translation must add a violation to the current
// translation because there might be untranslatable shared fields.
if ($saved_entity && $saved_entity
->getChangedTimeAcrossTranslations() > $entity
->getChangedTimeAcrossTranslations()) {
$this->context
->addViolation($constraint->message);
}
}
}
}