function EntityValidationException::__construct

Same name in other branches
  1. 9 core/modules/migrate/src/Exception/EntityValidationException.php \Drupal\migrate\Exception\EntityValidationException::__construct()
  2. 8.9.x core/modules/migrate/src/Exception/EntityValidationException.php \Drupal\migrate\Exception\EntityValidationException::__construct()
  3. 11.x 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())));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.