Entity Reference and Views: how to implement the "Referencing entity" relationship - drupal

I've got a main content type: "tournament", and a number of complimentary content types, e. g. "news", "judges", "participants".
A piece of news may relate to one or more tournaments or not relate to any tournaments.
Node type: News
Has field: Relevant Tournament(s)
↓
Node type: Tournament
The relation between tournaments and news should be set when creating a piece of news: you write news title, news contents and tick the relevant tournaments. So it's the complimentary node type that has the entity reference field.
On each tournament's page there should be a block that displays news relevant to the displayed tournament.
What i tried:
Created a Block View and put it to tournaments' pages.
Added a Contextual filter that retrieves tournament's Nid from URL.
Added an EntityReference Relationship (either "Referencing or "Referenced").
Set Format Style to Unformatted + Rendered Entity.
Attached either of Relationships to the Rendered Entity Format Style.
Also tried attaching Relationships to the Contextual filter.
But i failed to achieve the desired result.
I found a guide that might be relevant to my issue. But i failed to understand it because it involves PHP-hacking and is very Commerce-specific.

Okay, i got it figured out.
It wasn't working while i was using the "Rendered entity" Format Style.
When i changed to "Content" format style, it started working.
A complete recipe for reverse Views Entity Reference can be found here: http://drupal.org/node/1724396#comment-6406274

You can also check http://drupal.org/project/content_dependency
It provides automatic reversed referrals previews of different entity types.

Maybe an obvious question/answer:
Did you add a the "Content:rendered node" field to the fields of your view? You can refer to your Entity Reference Relationship (either "Referencing or "Referenced") in this field.
This might do the trick.. Otherwise, good luck!

Related

How to create a field consisting of a list of all nodes

Good day.
There is a problem: display news block on specific pages of any type of material.
I see the solution as follows: Create a field in the type of material "News" which will be displayed all the nodes (Title) with the possibility of using the mark checkboxes.
Who could help with advice: is it the right direction, and if yes - how to realize this field?
Thanks in advance for any help.
Download and enable Entity API and Entity reference modules.
Then go to your content type "Manage fields" page (admin/structure/types/manage/[CONTENT_TYPE]/fields) and add a new field of type Node reference. The rest of the configuration is left for your liking.

Displaying multiple fields on a "node reference field"

I've been struggling for a while with this problem and I'm curious if anyone has any thoughts:
I have two related content types on my website -- "Institutes" and "Projects". On a single Institute page I would like to display a preview of multiple Project content types that are related to that institute. This would mean for each preview pulling three fields from the Project page -- the main project picture, the title, and the project description.
Currently I have a "node reference" field on a Institute content type where you can select which Projects are related to the Person. Of course without Views it only shows the title of the Project. I just can't figure out how to use Views here to display the fields I want.
At this point I have a Block View with a Relationship selecting my node reference. I'm having trouble understanding how I can use that relationship to show fields of corresponding Project content types though.
Does anyone have any idea? I'm sure it's right in front of my face, I just need a push in the right direction.
Thank you so much in advance, to anyone willing to give advice.
-Maxime
Try this:
1) Create your view with the filter "Content Type: Projects" and configure the fields and display /style as usual...
2) Then add a argument of the "Institute reference field" or whatever you called on the Project page. Then set the default value of the argument to be "Node ID from URL"
When the block or whatever is displayed on a Institute page it will display the projects that reference it.
I hope I understood your question :)
I think you would have a user reference in your "Projects" content type instead of a node reference in "People" content type. Because you can create a view using arguments.
Try this things:
Delete the node reference in People.
Add a user reference content type in Proyecjs.
Create a view passing one argument: your user reference field.
Preview your view passing one example uid, i sure it workds.
I hope its useful.
Regards.

Author's nodes page with Views

I have a site where there can be more than one node author. My solution to this is a custom user reference field called additional authors, added to my content type. So if three people wrote an article, the person who publishes it, enters the other two into this additional authors field.
The problem I have is the following:
I'm trying to create a page (with Views) with the listing of all author's nodes - these can be either nodes where he is author OR nodes where he is referenced under additional authors. I want the author to be specified in the url (mysite.com/people/john-smith), but if I use contextual filters in Views, I can't seem to find the option to use OR - e.g. take author ID from url and show nodes where he is author of OR nodes where he is under additional authors.
I don't see any problem here:?? why you don't add the 'authors field' to your fields?
If you don't find it by the normal way look for it in 'Relationships'
Goodluck

Drupal create related node on node view

So if I have 2 custom content types book and review, I'd like a user(when viewing a specific book) to be able to create/attach a review to the book.
I've tried a few options.
1) Created a "create review" formblock and using panels made a custom node view panel for review, but I couldn't get the relationship to work.
2) I also tried overriding comments on the book type with the node type review, the problem with this is I'd like users to be also be able to comment on the book and I couldn't see the ability to add multiple comment types.
This seems pretty easy to do on node edit with node reference extension so I'm hoping this isn't a big ask.
You need nodereference and nodereference_url modules.
You can simply create a nodereference field in your review content type, and configure it with nodereference_url widget.
You partially answered your own question. With the nodereference module in D6 (or just references in D7), you can create a link in the same place 'add a comment' appears (the .links div) which says "add a review". This link is because "reviews" has a field called something like "book reference" which is a noderef field. This review will automatically fill in the field with the book where the user clicked the link and, depending on how you set the field up, send you back to the referenced node (book) or the new review.
You can find an interesting screencast there that show how to use Views Attach and Node Reference URL to do what you want :
http://mustardseedmedia.com/podcast/episode37

Drupal: Sub views?

I have a parent/child relationship (based on the cck node reference field).
Recipe Group contains a node reference to the type Recipe. It's a 1 to many relationship.
What I need to do is create a view that displays the recipe group information, and then under it, the recipes that have been assigned to it's cck field.
So
RecipeGroup1 - Title
Recipe1, Recipe2, Recipe3
RecipeGroup2 - Title
Recipe4, Recipe5, Recipe6
etc etc
I've created the view to pull the list of recipe groups.. but I have no idea how to retrieve the recipes that belong to the group?
I've tried googling, but we are on a tight time line and would appreciate any assistance.
Thanks.
Take a look at http://drupal.org/project/views_field_view. It lets you combine two views (groups, recipes), inserting the recipes view as a field into the groups view. Using this, you can have as many fields as you want for the group.
You can use the Views attach module to associate a view with a specific content type and display that view on that content type's node page.
There is a webcast here that demonstrates how the module can solve a problem similar to yours.
However, the webcast assumes your nodereference CCK field is on the child content type and is pointing to the parent content type, not the other way around like you have it.
Instead of using the nid of the recipe group as an argument to the view (as shown in the video) you may be able to use one of the recipe group's tokens (the nodereference field referencing its children). You can see that option at 9:32 in the video.
Whatever you decide to do, I think Views attach will likely be your answer.
Include the cck reference node field as an output field to your view. After, you can 'rewrite the output of this field'.. so that it looks however you want.
add noderefernce field in to views fileds
select check box to group field result in node ref field settings
theme that field as you want

Resources