Drupal 7 Entity Reference Multiple Display module

By shane
Wed, 2013-01-09 19:02
Daily Dose of Drupal Episode #84

Share with Others

The Drupal 7 Entity Reference Multiple Display Module extends the Entity Reference module by allowing you to differentiate the display anytime you are referencing multiple entities from one Entity Reference field. For example, if you reference 3 entities, you may want to display the first entity as the full entity, and the next two entities as teasers. This module allows you to do just that.

Note: I apologize for the audio issues with this video. Was having some issues with my microphone.

In this episode you will learn:

  • What the Entity Reference Multiple Display module can be used for
  • How to change the display mode of multiple referenced entities from a single entity reference field

Hello everyone and welcome to another Daily Dose of Drupal, today we’re on Episode Number 84. As always I’m Shane, you can follow me on Twitter at smthomas3, find me on Google + and go to codekarate.com and check out the other videos and sign up for the newsletter.

If you’ve been watching the Daily Dose of Drupal before you may have seen the Entity Reference Daily Dose of Drupal episode which was episode 7. This module that we’re going to go over today is the Entity Reference Multiple Display Module. It’s a relatively new module in drupal.org however it can be useful on some specific situations.

So the Entity Reference Module for a quick recap is just a way … it’s a Field type that can be used to reference different entities. So you may have one content type that you then need to reference another content type or maybe you need to reference specific users or any type of entity where it needs to go ahead and reference another type of entity and this could be used on any type of web application.

Maybe you need a CRM System where you have different content types like projects and you need to reference what type of client or which client the project is for. You could use something like the Entity Reference Field for that and there are of course many other users but that’s just one that came to my head but let’s go ahead and get started with this Entity Reference Multiple Display Module.

I have the Entity Reference Module installed right now and I added a content type called Test Entity Reference and it’s just a simple content type. All it has in it is the title and body field which comes by default and also this reference articles fields and it’s an Entity Reference Field, I have an Auto Complete Field and I have it Tag Style so it means we can reference it multiple and it’s pretty simple.

In the display right now I have it just the format is at Label so I went ahead and I created one called my Favorite Articles. So if I edit this you’ll notice that in this Reference Articles I have multiple articles, you can of course just start searching, it will pull them up and then you can use commas in between two of course Reference Multiple Articles in this case.

So I referenced those three articles, if I go to this page it just list these links because it’s referencing that these three entities are reference so I could say these are my favorite articles, I reference my three articles but let’s go ahead and say we want to actually display the articles on this page. So I can go into Content Types and go into this Test Entity reference and go to Manage Display and I can use this Rendered Entity and I can render it as a full content or the teaser, I’ll go ahead and select teaser and save it and if I come back here now you’ll notice that I have the three teasers in the order that I reference the articles in on this Edit screen.

So that looks great, however; there may be some situation where you have a list of these entities and let’s say you want this first one to be the full node and the second two will just to be the teasers or maybe you wanted the first two to be the teasers and just the last one will be the full node.

Whichever order you might want but you want these Reference Entities to be different formats. Well that’s where this Entity Reference Multiple Display comes in. So I’m going to go ahead and turn this module on and I will save this and all this is going to do is give me another option here if I go into Content Types and Test Entity Reference, we’ll go into Manage Display and it’s going to give me another format option.

Now there’s another option called Rendered Entity with Different View Modes. So now that I saved that I can then click on this or now that I selected that I can click on this little gear icon and I can select how many different groups I need and in this case I can … I’ll go ahead and say three.

The first one that I want to display is the full content and so only that one element so only the first one, the second one I want to display a Teaser and then the third and any following which you can use actually this number sign I want to display as the Search Result.

Obviously this isn’t necessarily a realistic example. Most likely maybe I just want the first one to be full content and the rest just to be a list of all the teasers but we can go ahead and set it as that, take a look at it so now that I save it I come back to this page you’ll notice it’s still my favorite articles node here and it has a list of reference articles. The first one you can see is a full node, the second one then is a teaser with a Read More link and then the third one is the Search Index or the Search Listing I guess. So if I come back here I can of course change that.

Let’s say I only want the first one to be the full content, the rest to be teasers, you can go ahead and set that and I will update and save it and now there’s a test article 1 and test article 2. You can see these two are teasers but this first one is the full content. So as you can see it’s a very simple module, it’s not something that you’re going to use on very many sites probably but if you do have something where you’re referencing multiple entities from one entity and you need to display them in different ways then … especially based on the order that you are referencing them so I reference this one first, this one is going to be a full content, the next two are going to be teasers and it’s not just limited to just full content and teasers that can of course we’ll go over the list here and the stuff that or all the different display options so you can have full content teaser RSS, Search Index or Search Result but you can go ahead and try this module out and use it if you need to render … reference entities differently based on the position that they’re referenced and go ahead and let me know if you find it useful. Thanks for watching the Daily Dose of Drupal; we’ll be back again next time with another episode. Bye!