I have a requirement to create an "associated media" field that can reference galleries (entity = node, bundle = gallery), videos (entity = file, bundle = video) or audio (entity = file, bundle = audio). This should be a single field with multiple values.

Any chance this is on the entity reference roadmap? I could certainly see others needing the same functionality.

Comments

Damien Tournoud’s picture

Status: Active » Closed (won't fix)

Thanks for your report, but no. Everything in Drupal assumes that you know the entity type to do anything useful (from the top of my head: Views integration, Entity metadata integration, Search API integration, CTools/Panels context integration, etc.). It's going to remain a constraint of the Entity Reference field that it can only reference a single entity type at once.

rickvug’s picture

In the end all I really need is a consistent data store for the references themselves as the display will be custom for each type of entity. It would be great to use Entity Reference for this but I understand the complexity and potential problems that adding this functionality would entail.

Anonymous’s picture

@rickvug - this is the perfect use case for the relation module.

rickvug’s picture

@kevee In the end I did go with relation. It is great from an API point of view but it is turning into a lot more work as the data isn't stored in the field itself. This means writing your own weight implementation for ordering as well as writing my own field widget to create and sort relation entities. Aside from these qualms I really like it though.

thetoast’s picture

I came across the same issue when trying out the relation module. I've actually created a widget that will group relations when setting maximum arity to infinite which will group the relations together into one relation entity, and then I'm attaching that relation id (the relation entity) to the content you're creating the grouped relations from, so in others words there's a parent container for the relation (sounds odd but it's a bit hard to explain my use case example), but anyway, this would then allow you to re-arrange the order of the relating content with the widget because infinite arity gives you deltas (weights, or endpoints_r_index as I think relations has it). But anyway, after stopping short of actually coding the re-arranging I stopped and had a go at the entity reference module. I seem to be having some issues with views though, I can't see entity reference fields I've created on custom entities that I created with the entity construction kit module. I used the eck module to quickly create some none node entities to test out the entity reference fields on those (because the project I'm working on has none node entities), but I'll create a new issue if I can't see the options I'm looking for.

thetoast’s picture

actually, after re-reading this issue and not being able to mix up the entity types, that's kind of scuppered any plans to use the entity reference module :-( Back to the relation module for the upteenth time :-). Have you checked out the relation select module? It looks promising, the module broke for me in a couple of places., but worth keeping an eye on.

bsandor’s picture

There's this EntityField Query Views Backend Module http://drupal.org/project/efq_views to check out. It used to handle multiple entity types also that feature was removed from it. Also it didnt support relationships originally however there's a way that is described in it's readme.txt.

http://drupal.org/node/1564740
http://drupal.org/node/1682710

elpino’s picture

nooooo... this was just the feature I was looking for, a way to reference either nodes or terms.

In my use case I need a way to display a linked image to featured content, be it specific nodes or taxonomy terms. My solution was having a View Slideshow of a custom content type that thus far holds an image file field, I was hoping not too use multiple entity reference fields (one for each entity type) as this would probably confuse the people managing the site.

Maybe the Link module could work, but I wouldn't have an autocomplete field or a way to get the referred node's title.

func0der’s picture

Issue summary: View changes

Try this module: entity_reference_multiple.

And apply this patch: https://www.drupal.org/node/2391787 and you have your multi entity reference field ;)
Please be aware that the module is in ALPHA stage and that the patch has not been approved yet.

nicrodgers’s picture

Incase anyone comes here from Google, looking for a D8 solution: https://www.drupal.org/project/dynamic_entity_reference

vinothg’s picture

Thanks @nicrodgers, dynamic entity reference is a good alternative.