protected EntityConstraintViolationList::groupViolationOffsets()
Groups violation offsets by field and entity level.
Sets the $violationOffsetsByField and $entityViolationOffsets properties.
File
- core/lib/Drupal/Core/Entity/EntityConstraintViolationList.php, line 60
Class
- EntityConstraintViolationList
- Implements an entity constraint violation list.
Namespace
Drupal\Core\Entity
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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'. list( $field_name ) = explode ( '.' , $path , 2); if ( $this ->entity->hasField( $field_name )) { $this ->violationOffsetsByField[ $field_name ][ $offset ] = $offset ; } } else { $this ->entityViolationOffsets[ $offset ] = $offset ; } } } } |
Please login to continue.