When Entity browser is used in IEF, cardinality defined on field is not propagated to Entity browser.
Way to reproduce (I have used EB Examples and also it requires IEF + EB IEF enabled):
1. on "Entity browser test" content type, change limit for "field_files" from unlimited to 2
2. for same field change form display widget -> to use Inline Complex
3. enable "Allow users to add existing file entities." and select same EB as it was used before.
--
4. create new "Entity browser test" content
5. choose "Add existing" and in EB select 3+ existing files
6. add them to IEF
=> all 3 will be added, button for adding new will be available (when you remove one file in IEF, button will be disappear, but as long it's N != Cardinality, button for adding new will be there).
I have found this issue during testing of: #2777747: [Needs tests] entity_form widget not updating after entity selection in entity_browser but it's not related with it. Fix from that issue just makes testing easier.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | entity_browser_cardinality.patch | 943 bytes | ayalon |
| #12 | interdiff.txt | 864 bytes | marcoscano |
| #12 | propagate-field-cardinality-2778923-12.patch | 1.04 KB | marcoscano |
| #10 | interdiff.txt | 1.18 KB | marcoscano |
| #10 | propagate-field-cardinality-2778923-10.patch | 1.09 KB | marcoscano |
Comments
Comment #2
slashrsm commentedTrue. Should be pretty easy task. We need to read this setting from field storage and set it on entity browser form element.
Comment #3
marcoscanoIs this the right place to add this?
Comment #6
marcoscanoComment #7
slashrsm commentedThis belongs to
entity_browser_entity_form_inline_entity_form_reference_form_alter().Comment #8
marcoscanoThanks for the feedback!
Another try, this time inside the form alter.
Comment #9
slashrsm commentedLooks good. Just one thing.
What if there are already entities selected? EB will still allow full number of entities, which will end up more than allowed. We should check how many entities are already selected and substract.
Comment #10
marcoscanoTrue!
Attached another try. Not sure on how to fetch existing entities selected, though. This works, but feels kind of ugly
Comment #11
slashrsm commentedIEF stores selected entities in the form state. You are able to get them with:
Comment #12
marcoscanoMuch better! :)
Thanks!
Comment #13
slashrsm commentedCommitted. Thanks!
Comment #15
ayalon commentedThis patch break the entity browser if used together with inline entity form.
The problem is, that you can only subtract the number of entities if the cardinality is NOT -1.
With this patch, the validation will fail, if you add 2 new items in the entity browser and later try to add an existing one with the entity browser.
Comment #16
ayalon commentedI submitted a patch here:
https://www.drupal.org/node/2799299#comment-11618949