function InvalidEntityException::__construct

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/DefaultContent/InvalidEntityException.php \Drupal\Core\DefaultContent\InvalidEntityException::__construct()

File

core/lib/Drupal/Core/DefaultContent/InvalidEntityException.php, line 16

Class

InvalidEntityException
Thrown if an entity being imported has validation errors.

Namespace

Drupal\Core\DefaultContent

Code

public function __construct(public readonly EntityConstraintViolationListInterface $violations, public readonly string $filePath) {
  $messages = [];
  foreach ($violations as $violation) {
    assert($violation instanceof ConstraintViolationInterface);
    $messages[] = $violation->getPropertyPath() . '=' . $violation->getMessage();
  }
  // Example: "/path/to/file.yml: field_a=Violation 1., field_b=Violation 2.".
  parent::__construct("{$filePath}: " . implode('||', $messages));
}

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