I posted about this in relation to Drupal 5 here. Now it's time to do this with Drupal 6...
Let's recap: Node reference field allows you to add a link from one content item to another. You add the reference to another existing node when you create a node with a nodereference field. The node being referenced must exist in order for this to work.
This bit of code lets you reference a non-existent node. The referenced node is created when the validation fails to find an existing node.
Some very basic code is attached. To try this, put the two files in a folder in your site modules folder. (see attached files). This code has been tested with Drupal 6 and CCK 2.
| Attachment | Size |
|---|---|
| noderefcreate.tar.gz | 1.93 KB |







I want to create all the fields!
Hey Darren, great module here.
I would love to enhance this idea by including the entire referenced node form into the main node form.
Use Case:
I have a content type "Song" with a field Lyrics.
I have a content type "Track" with a field Track #, and a node reference to a Song.
When a user goes to create a Track, I want them to be able to either select an existing Song, or create a new Song right there. Your module gets most of the way in that users can create the new Song content type title, but they can't fill in the lyrics.
Ideally I think the node reference field should be an either or: EITHER use the autocomplete text field, OR create a brand new node in a complete node form.
Do you think this is possible? Do you have any ideas for how to go about implementing it?
Thanks for your time!
Sara
another nodereference widget?
Yes, this is possible. There is a module for Drupal 5 that uses a popup window to create the node: http://drupal.org/project/addnode
I've not used the addnode module because it's not available for 6, and I wanted something really basic. In my case it would have been confusing for users to have to create another node and then reference it. That didn't make sense within the workflow for this particular site, I'm also not sure that having a popup window would have helped.
Could you:
1) validate the node reference using an AJAX callback, and using jQuery add in the other node form to create the referenced node? This could be in a modal popup (thickbox/lightbox) to force entry.
2) redirect to the newly created node's edit form on submit.
See also Popups Add and Reference
http://drupal.org/project/popups_reference
Remind user of newly created nodes
Hi,
Thanks for creating a very handy little module. The popups_reference module works well, but is a little complex for my needs, so this is ideal.
A quick suggestion to improve usability - I added a message to the user with links to the new nodes to remind them to finish filling them out:
After this line:
$nid = $newnode->nid;I added:
drupal_set_message(t('Added stub entry for '). check_plain($element['#title']) .': '. l($newnode->title, 'node/'. $nid));... although it strikes me that I should probably sanitize the title used in the link as well.
Will you add this to Drupal.org
I would love to see further development of this code. Are you interested in creating a d.o project?
Hi, I'm using your module and
Hi,
I'm using your module and it works great!
Thank you so much!
The Drupal 6 version has no Wikipedia extraction?
The D5 version worked just great -- but I upgraded to D6 and find that the node is created but there is no Wikipedia content. Just curious if that aspect is in the works? Is there any easy workaround for this?
There is another module, CreateFromWeb, which extracts Wikipedia and other content, but isn't unfortunately tied to nodereference. There is an issue on this, where I referred to your module ( http://drupal.org/node/387436 )
Thanks again.
Content Type
Hello there,
thanks for this great module! Works great so far (apart from a possible incompatibility with the links module bundle).
The only question i have is if it's possible to define the content type to be created.
So far i just can see that i can choose the content types to be references.
Best Regards
sonden
It creates a node of the
It creates a node of the content type that is to be referenced. It uses the first selected reference-able type.
I added this to d.o
http://drupal.org/project/noderefcreate
Content Type, seconded
Hello, thanks a lot for providing this module.
It creates a node of the content type that is to be referenced. It uses the first selected reference-able type.
What it seems to do is that it takes the content type it gets as the first result from a DB query, which is not necessarily the one wanted. Would it still be possible to add an option to choose the type to create?
My usage scenario:
I'm building a website for a scientific institute, where the staff can list their publications. Every publication can have several authors which are linked to staff profile nodes. But not all the authors are necessarily members of the institute, and therefore they will not all have nodes with their profiles on the site. For those external authors I would like to be able to not mix them with the staff members if possible (only a name is needed with those, and the nodes don't need to be published - in fact, I want to present the names unlinked). Now, when I add a dummy node type for external authors then I seem to be unable to choose that one as the type to create.
Apart from this, noderefcreate seems to work best in my case, out of all the similar modules I tried.
Hello, I'm using your module
Hello,
I'm using your module and it works great!
THANK YOU SO MUCH.. faiz oranları
Hello! I'm using your
Hello!
I'm using your module.
Thanks for creating this!
Works great!!!
Additional Fields
Hey Darren,
I'm looking to see if I can extend this module to either work with views (take a view of nodes to reference, with a content type selector to create nodes if none are found), or, alternatively, show an image next to the titles of nodes.
So, if I have an imagefield, theme that through theme_imagecache, and return that alongside the element title. I'm looking at the code and I'm a little confused on how to do this. Would you mind firing me an email with your thoughts? I'm happy to pay you for your time.
Thanks!
-Cameron
Post new comment