Drupal 7 Node Reference Tutorial
In this drupal video tutorial, we look at automatic node references in Drupal 7. Using the Node Reference Url, References, EVA and Views modules, we create an event registration system where our event nodes have a registration link for site visitors which automatically directs them to a registration form that is associated with the event. The tutorial takes it a step further and shows you how to list all registrants on the event node as well.
This tutorial is about 10 minutes long and expands on episode 37 of Mustard Seed Media's video podcast which shows similar functionality for Drupal 6.
NOTE: Since this video tutorial, Drupal 7.7 was released and a new version of views. To make this work in Views, the contextual filter has changed - you need to select 'add contextual filters' dialog, chose 'Content: Event(field_event)' and press the 'Add and configure contextual filters' button. In the next dialog chose 'Provide default value' option and you will be prompted with 'Type' combo box. Select 'Content ID from URL'. Hit 'Apply' and save the view definition. Big thanks to Rama for pointing this out!

Comments
Hello, first of all I would
Hello,
first of all I would like to thank you for this screencast. It helped me to set up an event registration on one of my websites. It works like a charm!
Unfortunately now we all want more (lol): Is it possible to limit the number of registrations for each event? So, if a maximum participant number of 30 is set and person number 31 wants to register, she/he will get a message, that the event is already full?
I tried to make it happen with rules, but it either cannot be achieved this way or I am simply too stupid to find out how.
I would really appreciate your answer and think more people would like to use such an additional feature.
Best wishes,
Kirsten
Hi Kirsten, thanks for the
Hi Kirsten,
thanks for the comment. I haven't done anything like but my first thought is to add a custom validation function to that node type with hook_node_presave. With the validation function, you could query the database to see how many existing registrations exist and if you're over your set limit, return an error back to the user with a message.
Let me know if that helps.
Pete
Hey, great tutorial. I was
Hey, great tutorial. I was following your tutorial and wanted to theme the link that is put on a page from nodereference_url. Ends up the module has a helper function called "nodereference_url_create_link" which is perfect! I was going to call that function within my tpl.php and wrap a div around that link so I could style it.... BUT I now get an error claiming that nodereference_url_create_link calls an undefined function "content_fields" which is like Druapl 7 Core!?
And ideas why this is blowing up. To test this, simply turn off the link when configuring the nodereference field url widget and then create a tpl.php for the content type (like "node--content_type.tpl.php") and add the following code to print your link (or rather not print it but watch the page blow up)...
nodereference_url_create_link($node, "field_name", "content_type_name");
What could be the problem? Do I need to include something from core so that the function gains access to that api function?
Hey Steve, thanks for the
Hey Steve,
thanks for the feedback on the tutorial.
As for the issue you are experiencing, that's a weird one. I'm not actually familiar with that function and don't see it listed on api.lullabot.org so can't easily check it out. I will review though and let you know.
On another note, typically, you want to keep all programming language out of your tpl files and in the template.php preprocess functions. I doubt it would make a difference but I would recommend using the function in a preprocess function and pass the results to the template file in a variable.
Pete
Hey mate you are rock :) This
Hey mate you are rock :)
This information and screen-cast is really helped me.
Thanks
The screencast is very
The screencast is very helpfull. Now I see what might be wrong: if you select an item for 'contextual filters', you also have options with 'Fields: xxxxxx'.
But I do not see those ? Strange.
I run on Drupal 7.7 with all required modules updated to the latest (I checked with Modules->Update).
Any idea why I cannot see the 'Fields: xxxx' options ?
I retried again with a fresh
I retried again with a fresh Drupal 7.7 install. Then added ctools plus views with drush. Then followed the steps in the screencast. The 'Fields: xxxxx' are not visible, only 'Content: xxxxx'. Because I cannot get this to work with 'Content: xxxx', I assume the 'Fields: xxxxx' must be used. But how to add these ?
Thanks for the podcast! It's
Thanks for the podcast! It's been very helpful! I'm having the same issue as Gijs is... Can't figure it out either...
same trouble here. (on a
same trouble here. (on a "playground" I am setting up a new project, where I need to make relations between 2 content types)
Making my View like in the screencast - I also don't have the option in "Contextual filters" to select "fields", just content etc.
Still the screencast was a bit helpfull thank you.
ur
Hi all, my apologies for the
Hi all,
my apologies for the late reply, I've been pretty swamped. I'll try and take a look at this in the next couple days and provide an update here. Thanks for support and patience.
Pete
I have a feeling that you may
I have a feeling that you may not be able to reproduce this tutorial with the latest drupal 7.7.
I am having the same problem - missing Fields in Filters drop down of the 'add contextual filters dialog. Which version of Drupal core did you use?
Thanks for the tutorial.
I figured this out. Looking
I figured this out. Looking through the list of changes made to the latest Views module I realized some of the implied relationships were taken out on purpose. Hence the missing Filter elements.
In the 'add contextual filters' dialog chose 'Content: Event(field_event)' and press the 'Add and configure contextual filters' button.
In the next dialog chose 'Provide default value' option and you will be prompted with 'Type' combo box. Select 'Content ID from URL'.
Hit 'Apply' and save the view definition. And enjoy the beauty of Drupal.
I had the same problem with
I had the same problem with 7.19. The way I finally made it work was by adding a relationship using the referenced field, and use the 'Content:referenced field' as a contextual filter. I also had to turn off 'Argument' in 'ENTITY CONTENT SETTING'. Hope this can help someone.
Hello! I have a problem with
Hello!
I have a problem with setting up my structure. I'll try make it simple:
ENVIRONMENT
- Drupal 7, node reference, views, eva, organic groups.
- Content types: Project, Basic Page.
- Field "node reference" in Project pointing at Basic Page, selecting one Project from combo.
- Opening Project page there is a Basic Page below.
- Created view "entity content" with contextual filter, using node reference of "webpage" in Project.
WHAT I HAVE:
Now to have what looks fine I have to extend Basic Page to have field "Represents project" where I choose Basic Page from combo. Then in view, contextual filter I select this node reference "Represents project". Then on Project Page I see wanted content of Basic Page.
How to make it working to select object for field "Webpage" (Basic Page object) in Project node and make it still work? Because now anyone who creates Basic Page will be able to maliciously mark any available Project as being represented by his Basic Page.. This will make a Project page with multiple unwanted content..
I know I could create field for HTML code in Project node, but for now it seems more reasonable to keep website of project separetely and reach them by node reference module..
I hope I described it clearly.
Also there is a thing like Node Reference widget. If I choose "Reference from URL" then field "Website" could be changed only once. Then it's read only field. So I am choosing "Select list" to avoid it. Maybe this is an obstacle in my way to what I described?
Cheers!
W
FIX: "Now to have what looks
FIX: "Now to have what looks fine I have to extend Basic Page to have field "Represents project" where I choose >>PROJECT<< from combo."
Great job! After looking
Great job! After looking around for 2 weeks to find a solution to my problem and almost giving up on it, I came across your video and it helped me BIG TIME! Now I got my site working the exact way I want it to.
THANKS A LOT! :D
I need to do in Drupal 7 the
I need to do in Drupal 7 the same that nodereference_explorer does in Drupal 6. Please help me.
Just wanted to say that this
Just wanted to say that this tutorial helped me so much and saved me so much time. This is exactly what I needed to setup a commenting and reviewing system that is more flexible than default comments module.
hey, thanks for the tutorial!
hey, thanks for the tutorial! I was absolutely lost when I downloaded EVA. now I have a place to start ;)
Thanks for this Screencast.
Thanks for this Screencast. I've been doing this in D6 for a while and it's to useful to leave behind in D7!
Thanks for those video
Thanks for those video tutorial.It is very easy to understand but i hope you can still add more manuals :D
Great tutorial! Am putting
Great tutorial! Am putting together an event system for our community and this really helped me out. Someone asked about this in the YouTube thread as well .... but I'm trying to figure out a way to limit them to signing up only once.
Any ideas?
Glad to hear it helped out!
Glad to hear it helped out! Unfortunately I don't really have the time to keep an eye on the youtube comments but I make and effort to respond here.
That said, to limit the sign up, you really need to have people register as users on the site (actually create a user account). it is possible to limit the sign up by creating a session cookie but having site registered users is really the most effective way to avoid issues (i.e., people could clear their cache if you are just using cookies and reregister. However this may not be a bad idea if your site is small...)
Maybe I'll have to cover it in a new tutorial...
Thanks!
pete
Hi There,i want to learn how
Hi There,i want to learn how to use drupal site.Unfortunately i am not familiar with that.
Thanks very much for taking
Thanks very much for taking the time and effort to put this together!!!
Very helpful!!!
Hello Pete, Please help me! I
Hello Pete,
Please help me!
I want to display the Product(content type) of particular user in a view on his profile!!
I mean i can do that with the
I mean i can do that with the user id! But can i do with the username pls?
Hi this tutorial is just the
Hi this tutorial is just the kind of thing i need for the site im building but my only problem is im using drupal 7.14 and my research has informed me that node reference is no longer needed and entity registration does the same thing, i have install the mod but can not find a good tutorial to show me how to impliment it just like you have done on your tutorial, i was hoping you might put up another tutorial using this module to enable me and others to register people on other sites for events also i was hoping that it would incorpate Kirsten Langholz request to limit the number of sign ups.
Great work with your tutorials, and i hope you can help
regards
Lee Andrews
Hi Lee, thanks for the
Hi Lee,
thanks for the comment and feedback. I'll take a look at the entity registration module - i've never used it but there's a first time for everything.
With regards to limiting registrations, I do have a tutorial in the queue on that, just started using the Node Limit module, http://drupal.org/project/node_limit, though not specifically for the purpose of event registrations. However, in the mean time before I have time to record that tutorial, I would recommend you check out that module to see if it fits your needs.
All the best,
pete
Awsome tutorial!! I fully
Awsome tutorial!!
I fully understand this tutorial it could have been for dummies.
I have tried to make one content type (header) that links 4 other content types (topics). It's like a weekly newsletter with 4 different weekly returning topics you can maintain by clicking a link for each topic. Maintaining the newsletter and the different topics works like a charm.
The problem:
I can't get a block for instance with different links. Each link named week nr** going to a page displaying the topics entered for that week.
I can't even get a page like the admin event page where you have the event on top with all the entries made listed below. Please help me?
Great screencast, thank you
Great screencast, thank you very much! But could you speak slower in future? :) I'm a native English speaker and the first ten words or so were indistinguishable!
This was a great tutorial, it
This was a great tutorial, it has solved some of my problems. However, when you create an EVA field in a view, and bundle it back to the content type (in this case your event). The link that appears on that content type for creating a new node of the second content type, is there any way to change who can see that? I have two content types I want linked, Profile and education/background. This is a many to one relationship, in that each person will have multiple entries in the education/background content type. Now, I only want specific individuals (ie the administer and the owner to create the entries in the education/background content type, but I would like to display the results for everyone to see. Is there a way of hiding the link for creating a new link, based on role or some other method.
Thanks for the great tutorials.
Scott.
great post new in d7 this
great post new in d7 this post help me a lot
Hello, Unfortunatelly this is
Hello,
Unfortunatelly this is not working anymore after installing the organic groups module. Anyone a work around or a bug fix for this?
Thanks,
Rodrigo
intersting to hear - what
intersting to hear - what exactly isn't working? can you share any additional information?
Hello, I'm just starting
Hello,
I'm just starting Drupal, so technically I'm nat advanced. This is the error message I get when I click on a generated link created by the first node:
Fatal error: Call to undefined function og_get_context_by_url() in D:\wamp\www\drupal-nl\sites\all\modules\nodereference_url\nodereference_url.module on line 178
On internet I found more reports on this error.
Thanks,
Rodrigo
Thanks - is your site online
Thanks - is your site online that i can take a look at it? and did you follow this tutorial exactly? what is it you are trying to accomplish?
Great tutorial! Thanks for
Great tutorial! Thanks for taking the time to create it for those of us stumbling upon similar issues.
I'm building a site using D7.17 and using OG to create a user profile content type (as the OG) and then attaching several additional content types for things like; work experience (job history), education (degree info), personal info, interests, etc. I have the build process down perfectly using Quicktabs to guide the user easily through the profile-build steps. My problem is that at the end of this process I end up with a bunch of nodes of various content types all associated with a specific user profile (group). I am then using another Quicktabs iteration to display various aspects of the user profile, and on one tab in particular I want to combine all of this information into a single view displayed on the tab.
I thought I could accomplish by simply adding all of the relationships to the view to bring in all of the various content type fields, but this didn't work. So I stumbled upon EVA and thought this would be the way to go. I turned to your tutorial to explain how EVA works, but for some reason when I go to create my view I do not get the "Entity Content" as an option for display types. So - I'm not sure where to go from this step. I do see EVA Field and Entity Reference as options. Are you aware of any changes that have taken place since you created the tutorial and possibly which of these options might replace the Entity Content option?
Thanks for your assistance. I'm going to play around with it and try the Entity Reference option to see if I get anywhere with that.
Okay - so it turns out that
Okay - so it turns out that the EVA Field has the same options described in your tutorial once I add that display type; however, after setting the contextual filter to OG from current context I am unable to get any content to display when entering a valid OG node ID for the auto-preview. Any thoughts?
DOH - turned out I had the
DOH - turned out I had the wrong content type selected - so in the latest version of Drupal (7.17 at the moment) and of EVA you simply use EVA Field as the display type instead of Entity Content - other than that it is pretty much the same. :)
You are awesome... I was
You are awesome...
I was trying to retrofit a version 6.x of View Attach. I was able to get one view attached but was not able to get multiple views attached. Using this module saved me a lot of time and frustration, thank you. One question with attaching multiple views attched to one node is how do I change the order in which they display. Is their a weight feature?
OMG, Just realized that the
OMG, Just realized that the views appear in order under the content display settings where you can drag the various Views attached around in the order you want. What about the links and reordering them, where is that done?
Thanks! It works.
Thanks! It works.
Well I have to say Thanks
Well I have to say Thanks Pete!
I just spent 5 hrs trying to get this to work for me. I was doing everything exactly the way you were.
I had 2 content types Realtor and Listing.
The Listing has node ref called realtor_reference.
I want the view to place the Realtor content on the Listing page.
THIS IS WHERE THINGS ARE DIFFERENT!!!!!! (Yes it took me 5 hrs to figure out that this is where it was different)
You were placing the view on the page being referenced and I am placing the view on the page doing the referencing. I thought this was worth noting for ppl struggling to get this to work in reverse.
So Heres what I did.
Entity Type = Node
Bundle = Listing
Argument = ID
*** Relationship*** Content: Realtor Reference (field_realtor_reference) - reverse *** There is a REVERSE LOOKUP!!!! Brilliant!!!
Contextual Filters = Node ID (default settings) But Select the Relationship created above.
Works Brilliantly!!
Thanks again
I thought I was going to have to write a module to do this for me but thanks to the wicked support from people on the IRC #Drupal-Support and People Like you Pete, I have saved myself a ton of coding! Its stuff like this that makes Drupal the Best Open source CMS on the Planet!
Hey CB, that's great to hear
Hey CB,
that's great to hear and I really appreciate you sharing the sticking point and the solution to it! Definitely agree, the Drupal Community is amazing - so many people willing to share their time to help others out. Awesome to be a part of it.
As an aside - i just spent something like 10 hours trying to get amazons cloudfront working to distribute my ubercart video tutorial series when purchased. pretty embarrassing and definitely frustrating but it happens. going to write up a post about it in case anyone else is looking for something similar.
Keep up the good work!
pete
nice tutorial.. very
nice tutorial..
very helpful..
thanks.
Now I'am happy! thank you
Now I'am happy! thank you
Thank you for the tutorial.
Thank you for the tutorial. It is useful.
At the end of it you develop a view to show a table of those registered for an event.
I am doing something similar but in my case it is a table of ratings for the main node.
At the bottom of this table I want to show some stats about the table of ratings.
Like # of ratings, average score, etc...
And for one of the roles I want to only show these stats not the details in the table.
Any hints would be greatly appreciated!
Bill
Thank a lot!
Thank a lot!
Hey, I was trying to solve a
Hey,
I was trying to solve a similar problem for hours, this video saved my butt, thanks!
Pages
Add new comment