function EntityConstraintViolationList::groupViolationOffsets
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Entity/EntityConstraintViolationList.php \Drupal\Core\Entity\EntityConstraintViolationList::groupViolationOffsets()
- 10 core/lib/Drupal/Core/Entity/EntityConstraintViolationList.php \Drupal\Core\Entity\EntityConstraintViolationList::groupViolationOffsets()
- 11.x core/lib/Drupal/Core/Entity/EntityConstraintViolationList.php \Drupal\Core\Entity\EntityConstraintViolationList::groupViolationOffsets()
Groups violation offsets by field and entity level.
Sets the $violationOffsetsByField and $entityViolationOffsets properties.
4 calls to EntityConstraintViolationList::groupViolationOffsets()
- EntityConstraintViolationList::filterByFields in core/
lib/ Drupal/ Core/ Entity/ EntityConstraintViolationList.php - Filters this violation list by the given fields.
- EntityConstraintViolationList::getByFields in core/
lib/ Drupal/ Core/ Entity/ EntityConstraintViolationList.php - Gets the violations of the given fields.
- EntityConstraintViolationList::getEntityViolations in core/
lib/ Drupal/ Core/ Entity/ EntityConstraintViolationList.php - Gets violations flagged on entity level, not associated with any field.
- EntityConstraintViolationList::getFieldNames in core/
lib/ Drupal/ Core/ Entity/ EntityConstraintViolationList.php - Returns the names of all violated fields.
File
-
core/
lib/ Drupal/ Core/ Entity/ EntityConstraintViolationList.php, line 60
Class
- EntityConstraintViolationList
- Implements an entity constraint violation list.
Namespace
Drupal\Core\EntityCode
protected function groupViolationOffsets() {
if (!isset($this->violationOffsetsByField)) {
$this->violationOffsetsByField = [];
$this->entityViolationOffsets = [];
foreach ($this as $offset => $violation) {
if ($path = $violation->getPropertyPath()) {
// An example of $path might be 'title.0.value'.
[
$field_name,
] = explode('.', $path, 2);
if ($this->entity
->hasField($field_name)) {
$this->violationOffsetsByField[$field_name][$offset] = $offset;
}
else {
$this->entityViolationOffsets[$offset] = $offset;
}
}
else {
$this->entityViolationOffsets[$offset] = $offset;
}
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.