entityTypeManager = $entity_type_manager; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('entity_type.manager') ); } /** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { $entity = !empty($value->getParent()) ? $value->getEntity() : NULL; if ($entity && !$entity->isNew() && !$entity->isDefaultRevision()) { /** @var \Drupal\Core\Entity\ContentEntityInterface $original */ $original = $this->entityTypeManager->getStorage($entity->getEntityTypeId())->loadUnchanged($entity->id()); if ($value->alias != $original->path->alias) { $this->context->addViolation($constraint->message); } } } }