3

I'm not sure why this is difficult for me to get. It seems like it should be simple. I have a content type A and content type B. Content type B has an entity reference field to content type A. Content type B has an image field.

I want to display a view of type A, with all the images of a type B that reference it.

I've looked everywhere and it isn't making sense. Can someone please point me in the right direction?

EDITED: I figure it may help if I give a concept of what I'm trying to do. I have programs that I want to display. For each program I have, one or more sponsors donate to the program. When I display my view, I not only want to display my program content (content A), but also the logos of all the sponsors that donate to the program (content type B). Right now, for each logo, I get a duplicate fields for my programs (content A).

  • in content type B are you using normal image field with unlimited number of values? – Aboodred1 May 10 '13 at 4:25
  • Just one value. It's a logo, so each content type B (sponsor) has one logo. – vintorg May 10 '13 at 4:33
  • what about entity reference field, is it unlimited number values? – Aboodred1 May 10 '13 at 4:41
  • The entity reference field does have unlimited values. – vintorg May 10 '13 at 4:59
5
+100

In your case i would use the EVA Field module in combination with Display Suite module.

The EVA field module provides an extra views display plugin (EVA Field Display) that allows you to attach a view dynamically to a node, user, term etc.

The Display Suite module works great with EVA and helps you by letting place the attached view any where you want within the node display layout.

Create a content view and add an EVA Field display. In the Entity Content Settings of this display select:

  1. Node for Entity type
  2. Content type A for Bundles
  3. Leave Arguments as it is (id)

Then:

  1. Add a relationship for the entity reference field you have on content type B referring to A
  2. Add the fields you want from content type B.
  3. Add filter for content type = content type B
  4. Add a contextual filter Content nid with the relationship of the entity reference!
  5. Go to query settings and check the Distinct setting.

Now what will happen is that for every node of type A an EVA field view display will be attached showing the corresponding fields of node type B. Using Display Suite you can place this attached view any where you want in the node layout.

Hope this helps.

  • I added the modules and followed your steps, but get no results back. The relationship I selected was referencing field (I assume that's the content B?). – vintorg May 10 '13 at 7:05
  • 1
    Make sure that the entity reference field you created belongs to type B and that it's referring to type A (Target type: Node, Entity selection: Type A). Then in views click add relationship, select Entity Reference from the drop down list and select the "Entity Reference: Referenced Entity" relationship with the description "A bridge to the Content entity that is referenced via field_xxx" where xxx is the label you gave to the entity reference field. Then while adding the contextual filter don't forget to select the relationship from the drop down list which is on the top of that window. – Billy May 10 '13 at 7:23
  • I started a new view and went back over my steps. I'm not getting any results back. – vintorg May 10 '13 at 7:48
  • Do you mean that you don't get results from the view or you don't see anything attached to the node A? If you don't get any results from the view itself then please remove the relationship and the contextual filter from the EVA view and tell me if you get any results. – Billy May 10 '13 at 8:06
  • I removed the contextual filter and relationship, and I now get a content type A result back. – vintorg May 10 '13 at 8:31
3

The following instructions might help you to solve your issue:

  • First add Entity Reference: Referenced Entity - content type B field (sponsor) - from Relationships menu.
  • Then add image field for content type B (sponsor) and select relationship from dropdown list - the relation you added in the first step.
  • Edit Title field Content: Title and check Exclude from display and apply.
  • Edit settings from Format menu and select Content: Title from Grouping field Nr.1 dropdown and make sure to check Use rendered output to group rows and apply changes.

The above solution will eliminate content type A (programmes) duplication.

  • It removed the duplicates, but the logos from my content B are not displayed. – vintorg May 10 '13 at 6:13
  • are you sure you selected relationship from drop down when you added/edit logo field from content type B – Aboodred1 May 10 '13 at 6:19
  • This may work, but it's a major pain on the formatting front. Most folks will have to do a tooooon of css hackery to get it to display nicely. – SuperJerms Jul 27 '13 at 18:45
  • @JDFandP If you're not developer/themer yes I agree – Aboodred1 Jul 27 '13 at 20:15
1

By using the rule module you could set up a view that when a page is viewed from Content A, it displays the images from Content B.

  • I feel like Views should handle it... – vintorg May 8 '13 at 4:43
  • Rules is just one way to do it I feel would be simple. It could also be done via views. Create a relationship under the view. You could then add contextual filters based on your needs. I sometimes struggle with figuring out what the perfect view criteria would be, when the solution could be done faster in rules. – CR47 May 8 '13 at 5:24
  • I need to learn the Views way first. – vintorg May 8 '13 at 11:11
0

In views you have to add a relationship.

Create a view that shows content of type A.

Add a relationship, which will be for the entity reference field you have on content type A.

Then add a field to the view that is the image field from content type B and select the relationship you previously added in the settings for that field.

Let me know if you need further clarification.

  • When you say "on content type A", you mean the reference from my type B to type A? I did that, but I get a duplicate of my content type A fields for each type B. – vintorg May 10 '13 at 1:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.