You are here

class EntityChangedConstraintValidator in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityChangedConstraintValidator.php \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityChangedConstraintValidator

Validates the EntityChanged constraint.

Hierarchy

Expanded class hierarchy of EntityChangedConstraintValidator

File

core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityChangedConstraintValidator.php, line 16
Contains \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityChangedConstraintValidator.

Namespace

Drupal\Core\Entity\Plugin\Validation\Constraint
View source
class EntityChangedConstraintValidator extends ConstraintValidator {

  /**
   * {@inheritdoc}
   */
  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);
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConstraintValidator::$context protected property 3
ConstraintValidator::buildViolation Deprecated protected function Wrapper for {@link ExecutionContextInterface::buildViolation} that supports the 2.4 context API.
ConstraintValidator::buildViolationInContext Deprecated protected function Wrapper for {@link ExecutionContextInterface::buildViolation} that supports the 2.4 context API.
ConstraintValidator::formatTypeOf protected function Returns a string representation of the type of the value.
ConstraintValidator::formatValue protected function Returns a string representation of the value.
ConstraintValidator::formatValues protected function Returns a string representation of a list of values.
ConstraintValidator::initialize public function Initializes the constraint validator. Overrides ConstraintValidatorInterface::initialize 1
ConstraintValidator::OBJECT_TO_STRING constant Whether to cast objects with a "__toString()" method to strings.
ConstraintValidator::PRETTY_DATE constant Whether to format {@link \DateTime} objects as RFC-3339 dates ("Y-m-d H:i:s").
EntityChangedConstraintValidator::validate public function Checks if the passed value is valid. Overrides ConstraintValidatorInterface::validate