I'm finding that if I have the widget mode set to 'Edit selection' and my field cardinality is set to 1, the 'Selections' in the modal can still display multiple files. I would expect that this not be the case.
It looks like the validation on the server doesn't really check this before just doing an array_merge to put the new selection in with the existing selections.
It is likely that the more general cardinality case wants to be solved here (i.e. cardinality > 1 and not infinite), but that's a different set of problems once you add in the prepend/append mode options etc. So I'm going to keep this ticket on track for this particular single selection problem.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | entity_browser-issue_with_selections-2825730-7.patch | 1.06 KB | rp7 |
| #5 | issue_with_selections-2825730-5.patch | 1.71 KB | amoebanath |
| #3 | issue_with_selections-2825730-2-3-interdiff.txt | 1.04 KB | amoebanath |
| #3 | issue_with_selections-2825730-3.patch | 1.57 KB | amoebanath |
Issue fork entity_browser-2825730
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
Comment #2
amoebanath commentedPatch!
Checks if there should be a cardinality validation of 1, and, if so, replaces the previous selection with the new selection (which has already been validated as a single selection).
Comment #3
amoebanath commentedThis seems to have brought up another issue a little further along. An easy fix, by the look of things.
Comment #4
amoebanath commentedHmm. Maybe this isn't the quick fix I thought.
The final selection value doesn't seem to save...
Comment #5
amoebanath commentedGotcha. When you submit the modal, the selections don't quite follow the same routes. So we just need to handle that scenario by checking on
$entitiesbefore handling that value.Comment #6
marcoscanoI have tried to manually reproduce the failing scenario you mention, but I am unable to do it with the current -dev.
Could you please indicate if this issue still exists, and if so, provide steps to reproduce it?
Thanks!
Comment #7
rp7 commented@marcoscano
According to me this issue still exists.
Pre-requisites:
If you select multiple items & try to add it to the selection, you will get an error message that only 1 item may be selected = OK.
Selecting 1 item & adding it to the selection works, but you can repeat this infinitely. Multiple items will be in the selection, while the field itself can only reference 1. If you submit the selection, only the first item is applied.
I see multiple solutions
I couldn't get patch in #5 to work. Patch attached goes for solution number 2 (see above). I'm wondering if the widget validators can't be used to validate the selection as well...
Comment #8
piotr pakulskiComment #13
mdranove commentedI had this same issue. patch in #7 works well, looks like a clean solution. Created MR and moving to NR. I think if we want to do some js work that should be done in a separate issue.
Comment #14
anybody@mdranove thanks! Could you check if #3177204: It's possible to overflow the number of allowed items with edit selection is a duplicate or should also be fixed by the MR?
Then we could push (both) things forward. Thank you!
Comment #16
anybodyComment #17
anybodyComment #18
mdranove commentedHi @anybody.
Yes looks like #3177204: It's possible to overflow the number of allowed items with edit selection is a duplicate issue, although the proposed resolution is different than what is done here. I tried the patch provided in the ticket and it throws an exception on my Drupal 10.2,
I recommend moving forward with this MR.
Comment #19
benstallings commentedNeeds merge conflicts resolved.
Comment #20
benstallings commentedComment #21
benstallings commentedComment #22
anybodyThanks!! I think it would make a lot of sense to have tests around this now.
Comment #23
benstallings commentedComment #24
benstallings commentedNew test: CardinalityTest::testSelectionDisplayCardinality().
Targets the new code path specifically rather than retesting the widget-level validator. Setup: cardinality-2 entity_reference field on article, wired to the bundle_filter browser (multi_step_display) in SELECTION_MODE_APPEND. The test selects three nodes one-at-a-time — each press is a single-entity batch that the widget-level Cardinality validator passes, but selected_entities grows to 3. Pressing "Use selected" then has to be rejected by SelectionDisplayBase::validate(); nothing else in the validation stack can catch it. Asserts the "You can only select up to 2 items" error.
Comment #25
anybodyThanks!! Tests are currently failing
Comment #26
benstallings commentedComment #27
benstallings commentedComment #28
anybodyThank you @benstallings! LGTM!
Comment #29
anybody