function EntityConstraintViolationList::groupViolationOffsets
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/EntityConstraintViolationList.php \Drupal\Core\Entity\EntityConstraintViolationList::groupViolationOffsets()
- 8.9.x 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 - EntityConstraintViolationList::getByFields in core/
lib/ Drupal/ Core/ Entity/ EntityConstraintViolationList.php - EntityConstraintViolationList::getEntityViolations in core/
lib/ Drupal/ Core/ Entity/ EntityConstraintViolationList.php - EntityConstraintViolationList::getFieldNames in core/
lib/ Drupal/ Core/ Entity/ EntityConstraintViolationList.php
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.