The autocomplete entity reference widget allows for the same entity to be referenced multiple times in the same field, it would be great if this widget would allow for that as well.
I have a use case where an editor might want to reference the same entity twice in the same field. This could be a content type which is made up entirely of references to other nodes/entities through one entity reference field. An example of this would be a node/entity containing contact information. The editor might want that contact information to appear at the top and bottom of a page consisting of references to other entities. So her workflow would be to reference the contact entity, reference the other entities, then reference the contact entity again in the same field.
Currently this module strips out duplicate entities in entityreference_view_widget_ajax(). But I think this should be up to the editor to decide whether or not she wants the same entity twice, not this module.
In addition, this module already provides a good way to prevent duplicate entities if they are not desired by excluding already referenced entities in the view with the "Pass selected entity ids to View" option. Since this setting is per field there is flexibility for site builders to determine when they might want duplicates or not.
I've removed the array_unique() function from entityreference_view_widget_ajax() and slightly restructured entityreference_view_widget_rows() to achieve this. Patch to follow.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | entityreference_view_widget-allow-duplicates-2301131-3.patch | 2.36 KB | jsacksick |
| #1 | entity_reference_view_widget-allow_duplicate_references-2301131-1.patch | 2.6 KB | jeni_dc |
Comments
Comment #1
jeni_dc commentedAdding patch.
Comment #2
jsacksick commentedWell, I'm not against that, but I think we should make that option configurable (Set to no by default).
Plus, I'm sure you can still load the entities once instead of loading them separatly (use $entity_ids instead of entities and do something like $entities[$id]; in the loop for the entity label.
This shouldn't be necessary.
You should probably use $entity_ids here instead of entities in order to have the same entity reference twice.
Comment #3
jsacksick commentedComment #5
jsacksick commentedSince there's no feedback, I decided to commit the patch.