3 namespace Drupal\Core\Entity;
5 use Drupal\Core\Session\AccountInterface;
6 use Symfony\Component\Validator\ConstraintViolationListInterface;
9 * Interface for the result of entity validation.
11 * The Symfony violation list is extended with methods that allow filtering
12 * violations by fields and field access. Forms leverage that to skip possibly
13 * pre-existing violations that cannot be caused or fixed by the form.
15 interface EntityConstraintViolationListInterface extends ConstraintViolationListInterface {
18 * Gets violations flagged on entity level, not associated with any field.
20 * @return \Drupal\Core\Entity\EntityConstraintViolationListInterface
21 * A list of violations on the entity level.
23 public function getEntityViolations();
26 * Gets the violations of the given field.
28 * @param string $field_name
29 * The name of the field to get violations for.
31 * @return \Symfony\Component\Validator\ConstraintViolationListInterface
32 * The violations of the given field.
34 public function getByField($field_name);
37 * Gets the violations of the given fields.
39 * When violations should be displayed for a sub-set of visible fields only,
40 * this method may be used to filter the set of visible violations first.
42 * @param string[] $field_names
43 * The names of the fields to get violations for.
45 * @return \Drupal\Core\Entity\EntityConstraintViolationListInterface
46 * A list of violations of the given fields.
48 public function getByFields(array $field_names);
51 * Filters this violation list by the given fields.
53 * The returned object just has violations attached to the provided fields.
55 * When violations should be displayed for a sub-set of visible fields only,
56 * this method may be used to filter the set of visible violations first.
58 * @param string[] $field_names
59 * The names of the fields to filter violations for.
63 public function filterByFields(array $field_names);
66 * Filters this violation list to apply for accessible fields only.
68 * Violations for inaccessible fields are removed so the returned object just
69 * has the remaining violations.
71 * @param \Drupal\Core\Session\AccountInterface $account
72 * (optional) The user for which to check access, or NULL to check access
73 * for the current user. Defaults to NULL.
77 public function filterByFieldAccess(AccountInterface $account = NULL);
80 * Returns the names of all violated fields.
83 * An array of field names.
85 public function getFieldNames();
88 * The entity which has been validated.
90 * @return \Drupal\Core\Entity\FieldableEntityInterface
93 public function getEntity();