You are here

public function EntityConstraintViolationList::getByFields in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/EntityConstraintViolationList.php \Drupal\Core\Entity\EntityConstraintViolationList::getByFields()

Gets the violations of the given fields.

When violations should be displayed for a sub-set of visible fields only, this method may be used to filter the set of visible violations first.

Parameters

string[] $field_names: The names of the fields to get violations for.

Return value

\Drupal\Core\Entity\EntityConstraintViolationListInterface A list of violations of the given fields.

Overrides EntityConstraintViolationListInterface::getByFields

1 call to EntityConstraintViolationList::getByFields()
EntityConstraintViolationList::getByField in core/lib/Drupal/Core/Entity/EntityConstraintViolationList.php
Gets the violations of the given field.

File

core/lib/Drupal/Core/Entity/EntityConstraintViolationList.php, line 106
Contains \Drupal\Core\Entity\EntityConstraintViolationList.

Class

EntityConstraintViolationList
Implements an entity constraint violation list.

Namespace

Drupal\Core\Entity

Code

public function getByFields(array $field_names) {
  $this
    ->groupViolationOffsets();
  $violations = [];
  foreach (array_intersect_key($this->violationOffsetsByField, array_flip($field_names)) as $field_name => $offsets) {
    foreach ($offsets as $offset) {
      $violations[] = $this
        ->get($offset);
    }
  }
  return new static($this->entity, $violations);
}