interface EntityConstraintViolationListInterface implements ConstraintViolationListInterface (View source)

Interface for the result of entity validation.

The Symfony violation list is extended with methods that allow filtering violations by fields and field access. Forms leverage that to skip possibly pre-existing violations that cannot be caused or fixed by the form.

Methods

getEntityViolations()

Gets violations flagged on entity level, not associated with any field.

ConstraintViolationListInterface
getByField(string $field_name)

Gets the violations of the given field.

getByFields(array $field_names)

Gets the violations of the given fields.

$this
filterByFields(array $field_names)

Filters this violation list by the given fields.

$this
filterByFieldAccess(AccountInterface $account = NULL)

Filters this violation list to apply for accessible fields only.

string[]
getFieldNames()

Returns the names of all violated fields.

getEntity()

The entity which has been validated.

Details

EntityConstraintViolationListInterface getEntityViolations()

Gets violations flagged on entity level, not associated with any field.

Return Value

EntityConstraintViolationListInterface

A list of violations on the entity level.

ConstraintViolationListInterface getByField(string $field_name)

Gets the violations of the given field.

Parameters

string $field_name

The name of the field to get violations for.

Return Value

ConstraintViolationListInterface

The violations of the given field.

EntityConstraintViolationListInterface getByFields(array $field_names)

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

array $field_names

The names of the fields to get violations for.

Return Value

EntityConstraintViolationListInterface

A list of violations of the given fields.

$this filterByFields(array $field_names)

Filters this violation list by the given fields.

The returned object just has violations attached to the provided 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

array $field_names

The names of the fields to filter violations for.

Return Value

$this

$this filterByFieldAccess(AccountInterface $account = NULL)

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

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

string[] getFieldNames()

Returns the names of all violated fields.

Return Value

string[]

An array of field names.

FieldableEntityInterface getEntity()

The entity which has been validated.

Return Value

FieldableEntityInterface

The entity object.