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, 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.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

koztunc created an issue. See original summary.

koztunc’s picture

Status: Active » Needs review
stomusic’s picture

Patch outdated, please re-roll it

stomusic’s picture

Status: Needs review » Needs work
jacobbell84’s picture

Version: 2.0.4 » 2.1.0-beta2
Status: Needs work » Needs review
StatusFileSize
new3.86 KB

Here's a re-roll for the patch

smustgrave’s picture

Version: 2.1.0-beta2 » 3.0.x-dev
Status: Needs review » Needs work

Should be in an MR

smustgrave’s picture

Actually since I added configuration validation in 3.0.x branch is this still needed?

smustgrave’s picture

Status: Needs work » Needs review

Take my previous statement back. I've updated slightly for 10.3

Will need a review from someone else besides myself.

pavel.bulat made their first commit to this issue’s fork.

pavel.bulat’s picture

The patch had an issue:

Error: Call to undefined method Drupal\Core\Field\BaseFieldDefinition::id() in limited_field_widgets_field_widget_third_party_settings_form() when you try to open the `Manage Form Display` tab with fields that were created on a code level.
For example: a Commerce Order has an Unlimited Order Items field. The field definition for the Order Items doesn't have id().

Steps to reproduce

1) Install Drupal Commerce and Commerce Order
2) Create a new order type
3) Open Manage Form Display tab

In the last commit, I added a check if ($field_definition instanceof FieldConfigInterface). It fixed the issue, but I am not sure that it was the right way to fix it, so feel free to review it.

  • smustgrave committed 5778736a on 3.0.x
    Issue #3201950 by koztunc, jacobbell84, stomusic, smustgrave: Implement...
smustgrave’s picture

Assigned: koztunc » Unassigned
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.