Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I have read several questions on topic, e.g. 1 2 3, but couldn't manage to get it work.

My setup: In a Drupal 7 environment, I have a node type called organizer, which contains two fields: node title (default) and a link (to the organizer's website). A second node type called event contains several fields one of which is an entity reference to organizer.

My site's design only has the node title and node body of an event being displayed in main content. All other fields are displayed in a sidebar using a views block with filter on node type (= event) and a contextual filter on node id. Among these fields is also the field organizer and it's displaying the organizer's name (title field) alright.

My goal: Now I want to have the organizer's name link to the organizer's website. But the link is actually a field inside the organizer content type.

My approach: I've added a relationship to Entity Reference: organizer. Then I added the link field that is used in the organizer content type to the list of fields using the relationship. I rearrange the fields to have this link field being loaded before the entity reference field. Then I set up the latter field to being rewritten as link using the plain url from the link field. [The link field is currently being displayed for debug purposes, later I want to exclude it from display, of course.]

My result: The link field is always empty. Hence, the organizer's name is never linked to the respective website.

Questions I stumbled upon: When I add a relationship, I have two options like

Entity Reference: Referenced Entity
A bridge to the Content entity that is referenced via field_organizer
 Entity Reference: Referencing entity
A bridge to the Content entity that is referencing Content via organizer

My understanding is that I have to user the first one, because I want to load the organizer that is referenced in the event. [The second one I would be using, if I have a organizer and want to get all events that are referencing this organizer, right?] However, I tried both options to no avail.

Is the ordering of fields relevant? I've tried both having the link field before and after the entity reference field, it stays empty in both cases.

Since each event could have more than only one organizer, the entity reference field is set to allow unlimited values. Could that cause a problem?

Could anyone point me into the right direction of what I am missing?


UPDATE: It seems to break the system if you have both relationship types set up at the same time or maybe the ordering plays a role, too. However, when the first relationship in list is the one I need it kind of works.

It is working absolutely fine for a single organizer, the name is displayed and linked to the organizer's website. But it will not work for any additional organizers. The block lists all organizers (when having more than one) but each of them is linked to the first organizer's website.

Thinking about how that works, that is reasonable, since the relationship only adds one related object. When displaying a field (e.g.) from that relationship it will be the same for each delta of entity reference field.

Actually, in that case I should be able to define how the entity reference field is displayed. It already has an option to link to the entity itself but you can't define any fields from the entity to be shown (e.g. instead of title).

share|improve this question
    
did you "use" the relation on the link field ? –  mojzis May 25 '12 at 8:32
    
Yes, indeed. When adding the link field I chose the respective relationship from the available dropdown. –  Paul May 25 '12 at 8:32
    
and is it still there ? if you were changing the relationships it could have vanished :) –  mojzis May 25 '12 at 8:40
    
Yes, it is still there. I might have found the issue, though, and will update question in a couple of minutes. –  Paul May 25 '12 at 8:44

2 Answers 2

The solution is a two step solution, but first you need to decided if you are going from Parent to Child or Child to Parent.

Background info

If you are going from Parent to Child, you setup a relationship using the "referenced" variable.

If you are going from Child to Parent, you setup a relationship using the "referencing" variable.

To make life simple for myself, when I specify the relationship, I also using the Administrative Option on the Reference Window and enter a more understandable name for the relationship. In you case, since I would make the Admin Name Event reading Organizer or something like that.

  1. Setup a relationship for Event reading Organizer in the Relationship field under the Advanced tab.

  2. Once you have related your Event content type to the Organizer content type, you should now be able to see the Organizer fields appear in your list of available fields. Select the fields from the Organizer content type that you want to appear in your view and hit Apply. Here is the CRITICAL part, once you have defined a Relationship, a new drop down menu (Relationship) will appear on the Configure field windows. For any fields that is in another table, you MUST choose the appropriate relationship for the field. In your case, you would choose the Event reading Organizer relationship. This relationship instructs view to go Organizer table and bring back that field. If you do not specify the relationship in the Configure field windows, this will not work.

Attached is a copy of the Configure field with a relationship. Note: In your example, you would want the referenced variable. But in my example, I was working with the referencing variable. Please do not let that confuse you. Just image the word in the relationship is referenced.

Views Configure Field windows

If you have any questions, please post them here and I will respond.

share|improve this answer
    
Thanks for sharing this. However, I already used this as you can see in the question's comments. And when "using" the relationship the problem is that it only works for the first relationship. That's why I had to come up with a completely different approach as described in my own answer (which btw. is more than 2 years old). –  Paul Jul 7 at 8:53
up vote 0 down vote accepted

I found a complete different approach which doesn't require relationships at all.

First, I installed the Display Suite module. It allows you to create new view modes for your content types. So, I created a new view mode called entity.

Next, I enabled this view mode in the desired content type (-> manage display) and only view the link field.

Further, I edited node.tpl.php (you can use also a more specific theme file like node--organizer.tpl.php) to hide the node title when the view mode is entity using an if construction:

<?php if ($page && $title && $view_mode != 'entity'): ?>
  <h1<?php print $title_attributes; ?>><?php print $title ?></h1>
<?php endif; ?>

Last, I edited the view and set the display option for the organizer field from Label to Rendered entity using the view mode entity.

Et voilà, the organizers are now displayed linking to the organizers' respective websites.

Note: This works for me because each link in a organizer node has its title set to the node title.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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