Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By dawehner on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.0.x
Introduced in version:
8.0.0-beta11
Issue links:
Description:
- Constrains which act on multiple fields can now be defined using
Drupal\Core\Entity\Plugin\Validation\Constraint\CompositeConstraintBase
. - There constrains can specify via the
coversFields()
method to which fields they apply to - Those constraints have to be added on the entity level - see https://www.drupal.org/node/2438011.
- Violations can be added to the respective fields with code like the following:
$context->buildViolation('Please enter a number between %min and %max.') ->setParameter('%min', 3) ->setParameter('%max', 10) ->atPath('number') ->addViolation();
- For an example, take a look at the CommentName constraint of the comment module.
Impacts:
Module developers