class EntityConstraintViolationList extends ConstraintViolationList implements EntityConstraintViolationListInterface (View source)

Implements an entity constraint violation list.

Traits

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Properties

protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected FieldableEntityInterface $entity

The entity that has been validated.

protected int[]|null $entityViolationOffsets

Violations offsets of entity level violations.

protected array[]|null $violationOffsetsByField

Violation offsets grouped by field.

Methods

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

__construct(FieldableEntityInterface $entity, array $violations = [])

{@inheritdoc}

groupViolationOffsets()

Groups violation offsets by field and entity level.

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.

add(ConstraintViolationInterface $violation)

{@inheritdoc}

remove($offset)

{@inheritdoc}

set($offset, ConstraintViolationInterface $violation)

{@inheritdoc}

Details

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

__construct(FieldableEntityInterface $entity, array $violations = [])

{@inheritdoc}

Parameters

FieldableEntityInterface $entity

The entity that has been validated.

array $violations

The array of violations.

protected groupViolationOffsets()

Groups violation offsets by field and entity level.

Sets the $violationOffsetsByField and $entityViolationOffsets properties.

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.

add(ConstraintViolationInterface $violation)

{@inheritdoc}

Parameters

ConstraintViolationInterface $violation

remove($offset)

{@inheritdoc}

Parameters

$offset

set($offset, ConstraintViolationInterface $violation)

{@inheritdoc}

Parameters

$offset
ConstraintViolationInterface $violation