Drupal create related node on node view - drupal

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

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

Creating list of similar nodes in Drupal 7/Views 3

Copy from drupal.stackexchange.com hoping to get more answers here:
I face a rather common problem of displaying a list of nodes similar to current one. Similar node is defined as one having at least one taxonomy term that current node has. There are few solutions available as modules, however the modules I've found (specifically Similar By Terms) are in beta stage (as in "not working properly") for Drupal 7.
I've also found a couple of solutions based on Views and contextual filters (such as http://scito.ch/content/show-related-nodes-block-based-taxonomy-terms-views-3-and-drupal-7) or relations. I quite like this way as it saves me installing extra modules and with Views being actively developed and supported I'd prefer to use them rather than any custom solution. The problem I can't get around is how to sort "similar nodes" by the number of terms they share. For example, if I have "IPhone 4S" Node with Terms "Gadget", "Apple", and "Phone", I want similar nodes in the following order:
IPhone 3 (Apple, Gadget, Phone)
IPad (Apple, Gadget, Tablet)
Mac (Apple, Computer)
Bramley (Apple, Fruit, Tree)
How can I sort nodes in this view by the number of terms they share?
This question is about building a view, please do not suggest module or custom php-based solutions. Thank you.
Create a block view
Add Contextual filter -> Content: Nid -> Provide default value -> Content ID from URL
Add Relationship -> Content: Taxonomy terms on node -> specify the appropriate vocabulary
Add Relationship -> Taxonomy term: Content using vocabulary as specified above -> Check off Require this relationship
Turn on Views aggregation (NOTE: the arrow in the screenshot below is pointing to the wrong spot and should be pointing to 2 rows below where it is)
Assuming you are listing title only, edit the title field to use the Relationship you set up in #4 above.
Add new sort criteria of Content: Nid. In aggregation settings, select Count. Use relationship from #4 and sort descending
Add Contextual filter -> Content: Nid -> Use relationship from #4 -> Provide default value - Content ID from URL -> Scroll down and expand "More" then check "Exclude" to remove current node from the view
** See comment by #garret-albright below for testing this in the Views UI preview. **
guess what - there are modules for that too :D
i can recommend similar by terms giving you that view without configuration hassle.
When you are configuring complex views like this one, there are some configuration tips that may help you to understand what is really going on each step:
In Structure >> Views >> Settings >> Basic:
Check 'Show advanced help warning' (important: requires Advanced Help module installed)
Check 'Automatically update preview on changes'
Check 'Show information and statistics about the view during live preview'
Check 'Show the SQL query'
and finally, Save configuration
Now you can preview the results from each configuration step, the SQL query associated and the fields and tables involved, so you will find easier to understand how filters and aggregations work.
Hope it helps.
This is an alternative solution, related to this question. However it might not apply to every case, but if you can use it it's simpler (and safer than aggregation in my opinion).
I am going to use panels. Once you create a panel to show your entity (node or anything else) you can add multiple views and show them beside the content. one of these views is going to be our related content.
Thus panels is the only limitation. Maybe it's possible to use mini-panels and represent it as a block, I haven't tried myself.
Prerequisites
Views (d'oh!)
Panels
Views Content Pane: no need to download, It is in ctools module downloaded with views.
Page manager: Same as Views Content Pane (Optional / Highly Recommended).
The view
Create your view as you normally would, but do not create it as a block or page. Uncheck both.
In views configuration page create a relation to taxonomy term on the entity.
Create a contextual filter to filter: Taxonomy term: Term ID.
Create another contextual filter: Entity ID or Content: Nid if it's a node.
While creating this one, at the bottom there is a collapsed fieldset which has the option: Exclude. Check it as marked.
Now by clicking Add create a new display of type Content pane.
In the display configuration area (named: Pane settings) open Argument input. You should have 2 options:
Content: Nid source : Set it's source as From context. Set it's Required context as Content ID (if you are not using node it can be ID.
Taxonomy term: Term ID source : Set it's source as From context. Set it's Required context as Term ID.
Congrats! You are done creating your view. It's time for a panel (I wont explain much about creating a panel as it is beyond the scope of this Q/A).
The Panel
Create a panel (or enable the node/%node default panel and add a variant).
In context tab, Create a relation to taxonomy term on the entity.
Click add content in one of panes.
If you didn't change the view's category, it's in views pane add it. It will ask for an Entity ID and Term ID both are available now in your panels context, set them.
Now when the panel is displayed, All the content with with the same term excluding the content on this page are displayed.
Views Configuration
Contextual filter
Argument input
Important P.S:
This method is tried and it works flawlessly, but at the time of writing this article ctools had a bug. There is a patch for it: https://www.drupal.org/node/2195211
I am not sure if I fully got the gist to your question but I think node queue is the answer. Check out http://drupal.org/project/nodequeue
The module is well developed. I have used it for a client and you can use their smartqueue api too make make your list.
Hope I was helpful.

Drupal Views of nodes to show node comments

I've encountered a Drupal problem: I'm using the Views module for rendering nodes of a kind, based on the user id of it's author (it is a Content Profile actually). I want the view to show the comments for the node, just like in node/%. I could not find any option in views or any relevant module. Am I in the wrong direction and should reorganize stuff for this...?
Any ideas, how can it be done?
Regards,
Laci
Using views is really not the best plan of action. You should instead create a node template in your theme and customize it. If needed you can put some logic in a preprocess function. It requires more coding but will get you where you want.
If you use view node display type
Check in it's settings show comments
if you use view fields display type
Use relationship to comments and select fields you need and theme them
I know this is old request, but I was just struggling with the same issue and came across this post. I thought it'd be helpful to share my solution.
I'm using Drupal 7, with Views 3 and Display Suite.
In your view, choose the display in question.
Under Format, click the first link to the right of 'Show'.
Choose 'Content' (or 'Display Suite' in my case).
Click 'Apply'.
On the next screen, you'll have the option to 'Display comments'. Check this box and save your view.
You should now see the comments displayed under each item in the view.
You could create a second view (with URL e.g. /comments/% where the placeholder will be the node ID, and not the comment ID) that lists comments for a given node, with a contextual filter to only show them based on the NID in the URL.
Then, add that view to the footer (as a 'view area') of the single-node view you've already got.
There's some tweaking required for layout (inline fields etc.) but the basic structure should work.

Resources