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).