Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. EntityValidationException.php

function 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())));
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal