// Add two violations to two specific fields.
$violations[] =
new ConstraintViolation('test name violation', '',
[], '', 'name', 'invalid', NULL, 'test-code-violation-name'
);
$violations[] =
new ConstraintViolation('test name violation2', '',
[], '', 'name', 'invalid', NULL, 'test-code-violation2-name'
);
$violations[] =
new ConstraintViolation('test type violation', '',
[], '', 'type', 'invalid', NULL, 'test-code-violation-type'
);
$violations[] =
new ConstraintViolation('test type violation2', '',
[], '', 'type', 'invalid', NULL, 'test-code-violation2-type'
);
// Add two entity level specific violations.
$violations[] =
new ConstraintViolation('test entity violation', '',
[], '', '', 'invalid'
);
$violations[] =
new ConstraintViolation('test entity violation2', '',
[], '', '', 'invalid'
);
return new EntityConstraintViolationList($entity,
$violations);
} /**
* Builds an entity constraint violation list with composite constraints.
*
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
* A fieldable entity.
*
* @return \Drupal\Core\Entity\EntityConstraintViolationList
* The entity constraint violation list.
*/