Implement custom validation constraint

Created on 5 March 2021, over 3 years ago
Updated 5 September 2024, 15 days ago

In limited_field_widgets, enforcement of the custom cardinality setting is only done through #element_validate on the widget form. As described in #1029298-99 ✨ Allow cardinality to be restricted (overriden and reduced) in the field instance settings Active , this excludes entity updates through, say, the REST API. This patch implements a custom validation constraint to limit the cardinality of field instances. The validation constraint ensures that all entity updates are validated against the limit_values setting. The patch does not replace the current form validation, which takes precedence as it is performed earlier in the update operation.

Possible sticking points with this patch are:

  1. The added functionality has only been tested with Paragraph bundles. limited_field_widgets_limit_validation guards against certain edge cases such as the _none item, which haven't been implemented in the new validation constraint. I've been unable to find exactly which behaviors necessitate these additions, so I've been unable to test whether they work with the constraint.
  2. The pre-patch third party setting was held in the field widget, and the patch includes some code to synchronize that value to another third party setting in the field config, which is needed to access the setting from hook_entity_bundle_field_info_alter(). This code works fine from my testing, but it might be worth taking a second look at.

Any feedback and additional testing is appreciated.

✨ Feature request
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States koztunc

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024