class EntityValidationException in Drupal 8
Same name and namespace in other branches
- 9 core/modules/migrate/src/Exception/EntityValidationException.php \Drupal\migrate\Exception\EntityValidationException
To throw when an entity generated during the import is not valid.
Hierarchy
- class \Drupal\migrate\MigrateException extends \Drupal\migrate\Exception
- class \Drupal\migrate\Exception\EntityValidationException
Expanded class hierarchy of EntityValidationException
1 file declares its use of EntityValidationException
- EntityContentBase.php in core/
modules/ migrate/ src/ Plugin/ migrate/ destination/ EntityContentBase.php
File
- core/
modules/ migrate/ src/ Exception/ EntityValidationException.php, line 13
Namespace
Drupal\migrate\ExceptionView source
class EntityValidationException extends MigrateException {
/**
* The separator for combining multiple messages into a single string.
*
* Afterwards, the separator could be used to split a concatenated string
* onto multiple lines.
*
* @code
* explode(EntityValidationException::MESSAGES_SEPARATOR, $messages);
* @endcode
*/
const MESSAGES_SEPARATOR = '||';
/**
* The list of violations generated during the entity validation.
*
* @var \Drupal\Core\Entity\EntityConstraintViolationListInterface
*/
protected $violations;
/**
* EntityValidationException constructor.
*
* @param \Drupal\Core\Entity\EntityConstraintViolationListInterface $violations
* The list of violations generated during the entity validation.
*/
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())));
}
/**
* Returns the list of violation messages.
*
* @return string[]
* The list of violation messages.
*/
public function getViolationMessages() {
$messages = [];
foreach ($this->violations as $violation) {
assert($violation instanceof ConstraintViolationInterface);
$messages[] = sprintf('%s=%s', $violation
->getPropertyPath(), $violation
->getMessage());
}
return $messages;
}
/**
* Returns the list of violations generated during the entity validation.
*
* @return \Drupal\Core\Entity\EntityConstraintViolationListInterface
* The list of violations generated during the entity validation.
*/
public function getViolations() {
return $this->violations;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityValidationException:: |
protected | property | The list of violations generated during the entity validation. | |
EntityValidationException:: |
public | function | Returns the list of violation messages. | |
EntityValidationException:: |
public | function | Returns the list of violations generated during the entity validation. | |
EntityValidationException:: |
constant | The separator for combining multiple messages into a single string. | ||
EntityValidationException:: |
public | function |
EntityValidationException constructor. Overrides MigrateException:: |
|
MigrateException:: |
protected | property | The level of the error being reported. | |
MigrateException:: |
protected | property | The status to record in the map table for the current item. | |
MigrateException:: |
public | function | Gets the level. | |
MigrateException:: |
public | function | Gets the status of the current item. |