Here's a few bits of code from today's Drupal wranglings that solves a tricky UX problem with Drupal and CCK Node Reference fields.
Ever wanted to deal with the case that a user might want to reference a node that doesn't exist yet? Well I've played around with a couple of modules (Add n Reference and Add Node), but they didn't offer the clean user experience I needed. Here's an example use-case:
When creating a node of type gig, the user needs to enter artists that are playing. These artists are linked via node referrence fields in the data model. The select list widget is no good, because there will be thousands of possible artists. The autocomplete widget is better, but (a) requires that the artist node already exists, and (b) appends a string with the nid (node ID) to the end of the users input (which from user feedback they find confusing).
I've adapted the node reference widget to solve both of these issues:
(a) it allows the user to reference a node that doesn't exists. In this case it creates a new node with the body text taken from the first matching Wikipedia entry. The idea is that this is just seed content, and the user will eventually update the content for themselves.
(b) i removed the nid requirement from the autocomplete callback.
There are some major improvements to make soon, but this will work for the time being. Eventually I want to give the user options to "disambiguate" the response - for example: if multiple possible matches are found then show a drop down select, and use the MediaWiki API to pull content from Wikipedia, giving the user option to select from a few similar articles if the correct article is not obvious.
Check out the attached file for the basics of the module. This is just a preview, as there's some domain specific code still in there (e.g. I also import artist images from Wikipedia). This will be made more universal when I produce the final version of the module, but you may need to comment this out for now.
| Attachment | Size |
|---|---|
| autocomplete_noderef-PREVIEW.tar.gz | 4.38 KB |







¿How I use this preview?
Hi:
I´am a new Drupal developer and I really need something like this. But I dont know how and where use your code.
Some help? and... thanks a lot
This code is very
This code is very developmental and not really usable just yet. You should be able to preview the functionality by installing as a module.
There are comments in the code as to where you can insert your own content import code.
Let me know if there's anything specific you need help with.
Is this drupal 5 or 6 compatible?
What version of drupal and cck is this compatible with?
Looks like drupal 5
Okay, looks like drupal 5
That's Correct
Yep, I'm using it on 5.7/5.8 with latest version of CCK.
This looks like being a
This looks like being a fantastic module. I know it's only a preview but could you shed some light on why I get this SQL error:
user warning: Unknown column 'n.body' in 'where clause' query: SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions r ON r.vid = n.vid WHERE n.title = 'New Venue' AND n.type = 'venue' AND n.uid = '1' AND n.body = 'Description goes here' AND n.status = '1' AND n.is_new = '1' AND n.nid = '3' AND n.vid = '3' AND n.created = '1217801784' AND n.changed = '1217801784' in /Applications/MAMP/htdocs/drupal5/includes/database.mysql.inc on line 172.I've been having a play with it after commenting out the calls to the Wikipedia fetching functions etc. For nodes which exist, it goes without a hitch but for nodes which it has to create I get the above error. The new nodes still get created though.
I get the same SQL error -
I get the same SQL error - it is because the query is looking for the column node.body, but the body column is stored in the revisions table, so I think it should be node_revisions.body (or r.body), but I'm not sure where the query originates.
Other than that, the module works really well, although maybe the Wikipedia scraping could be optional?
have you looked at autonode?
have you looked at autonode?
yes, I had a quick play with
yes, I had a quick play with autonode... but it does depend on the source data being in a reference table. I suppose this could be extended to allow for other alternatives? or perhaps we could create an autonode API to allow different scenarios to be plugged in?
This is exactly what I am
This is exactly what I am looking for! Is there a solution for Drupal 6?
This might help
This might help you:
http://www.darrenmothersele.com/drupal-blog/node-reference-create-drupal...
Thks Sohbet
thanks brother.nice sharing..veryy goood.
Post new comment