You are here

public function EntityValidationException::__construct in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate/src/Exception/EntityValidationException.php \Drupal\migrate\Exception\EntityValidationException::__construct()

EntityValidationException constructor.

Parameters

\Drupal\Core\Entity\EntityConstraintViolationListInterface $violations: The list of violations generated during the entity validation.

Overrides MigrateException::__construct

File

core/modules/migrate/src/Exception/EntityValidationException.php, line 40

Class

EntityValidationException
To throw when an entity generated during the import is not valid.

Namespace

Drupal\migrate\Exception

Code

public function __construct(EntityConstraintViolationListInterface $violations) {
  $this->violations = $violations;
  $entity = $this->violations
    ->getEntity();
  $locator = $entity
    ->getEntityTypeId();
  if ($entity_id = $entity
    ->id()) {
    $locator = sprintf('%s: %s', $locator, $entity_id);
    if ($entity instanceof RevisionableInterface && ($revision_id = $entity
      ->getRevisionId())) {
      $locator .= sprintf(', revision: %s', $revision_id);
    }
  }

  // Example: "[user]: field_a=Violation 1., field_b=Violation 2.".
  // Example: "[user: 1]: field_a=Violation 1., field_b=Violation 2.".
  // Example: "[node: 19, revision: 12129]: field_a=Violation 1.".
  parent::__construct(sprintf('[%s]: %s', $locator, implode(static::MESSAGES_SEPARATOR, $this
    ->getViolationMessages())));
}