EntityConstraintViolationListInterface.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace Drupal\Core\Entity;
  3. use Drupal\Core\Session\AccountInterface;
  4. use Symfony\Component\Validator\ConstraintViolationListInterface;
  5. /**
  6. * Interface for the result of entity validation.
  7. *
  8. * The Symfony violation list is extended with methods that allow filtering
  9. * violations by fields and field access. Forms leverage that to skip possibly
  10. * pre-existing violations that cannot be caused or fixed by the form.
  11. */
  12. interface EntityConstraintViolationListInterface extends ConstraintViolationListInterface {
  13. /**
  14. * Gets violations flagged on entity level, not associated with any field.
  15. *
  16. * @return \Drupal\Core\Entity\EntityConstraintViolationListInterface
  17. * A list of violations on the entity level.
  18. */
  19. public function getEntityViolations();
  20. /**
  21. * Gets the violations of the given field.
  22. *
  23. * @param string $field_name
  24. * The name of the field to get violations for.
  25. *
  26. * @return \Symfony\Component\Validator\ConstraintViolationListInterface
  27. * The violations of the given field.
  28. */
  29. public function getByField($field_name);
  30. /**
  31. * Gets the violations of the given fields.
  32. *
  33. * When violations should be displayed for a sub-set of visible fields only,
  34. * this method may be used to filter the set of visible violations first.
  35. *
  36. * @param string[] $field_names
  37. * The names of the fields to get violations for.
  38. *
  39. * @return \Drupal\Core\Entity\EntityConstraintViolationListInterface
  40. * A list of violations of the given fields.
  41. */
  42. public function getByFields(array $field_names);
  43. /**
  44. * Filters this violation list by the given fields.
  45. *
  46. * The returned object just has violations attached to the provided fields.
  47. *
  48. * When violations should be displayed for a sub-set of visible fields only,
  49. * this method may be used to filter the set of visible violations first.
  50. *
  51. * @param string[] $field_names
  52. * The names of the fields to filter violations for.
  53. *
  54. * @return $this
  55. */
  56. public function filterByFields(array $field_names);
  57. /**
  58. * Filters this violation list to apply for accessible fields only.
  59. *
  60. * Violations for inaccessible fields are removed so the returned object just
  61. * has the remaining violations.
  62. *
  63. * @param \Drupal\Core\Session\AccountInterface $account
  64. * (optional) The user for which to check access, or NULL to check access
  65. * for the current user. Defaults to NULL.
  66. *
  67. * @return $this
  68. */
  69. public function filterByFieldAccess(AccountInterface $account = NULL);
  70. /**
  71. * Returns the names of all violated fields.
  72. *
  73. * @return string[]
  74. * An array of field names.
  75. */
  76. public function getFieldNames();
  77. /**
  78. * The entity which has been validated.
  79. *
  80. * @return \Drupal\Core\Entity\FieldableEntityInterface
  81. * The entity object.
  82. */
  83. public function getEntity();
  84. }