You are here

public function EntityConstraintViolationList::filterByFieldAccess 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::filterByFieldAccess()

Filters this violation list to apply for accessible fields only.

Violations for inaccessible fields are removed so the returned object just has the remaining violations.

Parameters

\Drupal\Core\Session\AccountInterface $account: (optional) The user for which to check access, or NULL to check access for the current user. Defaults to NULL.

Return value

$this

Overrides EntityConstraintViolationListInterface::filterByFieldAccess

File

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

Class

EntityConstraintViolationList
Implements an entity constraint violation list.

Namespace

Drupal\Core\Entity

Code

public function filterByFieldAccess(AccountInterface $account = NULL) {
  $filtered_fields = array();
  foreach ($this
    ->getFieldNames() as $field_name) {
    if (!$this->entity
      ->get($field_name)
      ->access('edit', $account)) {
      $filtered_fields[] = $field_name;
    }
  }
  return $this
    ->filterByFields($filtered_fields);
}