Skip to content

My Drupal Conundrum

June 19, 2009

I’ve spent a good portion of the day today trying to duplicate – in Drupal – something that I can build in about 30 minutes by directly writing source code. At this stage, I’m going to throw this out to the Internet in the hope that someone else can help me figure out what I’m missing.

Several years ago I worked on a team that took the Herrick Building Archives online. This archive is a complete history of every structure that’s ever existed at Ohio State. The central focus of the archive is a building record – like this record for Ives Hall, former home of the Knowlton School of Architecture (where I work).

A building record is comprised of two basic pieces of content: the core building record, and zero or more addenda that were written each time the building was renovated.

To accomplish this in Drupal, I used CCK to create two content types: Building (for the core record) and Addendum (for each addendum. The Addendum content type has a node reference field back to its parent Building, which establishes the data relationship. When I coded this by hand, the addenda table had a foreign key back to the building table ID field.

The display page on the original site, then, essentially followed this structure:

  1. Get Building ID from querystring
  2. Look up core building record (date, text, etc) from building table; print that information
  3. Look up all records from the addenda table which reference this building record (i.e. “SELECT * FROM tbladdenda WHERE BuildingID = 7”)
  4. Loop through that recordset and print out the addenda text for each record

Easy, to the point of trivial. But how to do this in Drupal?

My first thought was to build a View, and take advantage of Tokens. Build a View that looks up all addenda which reference the current building ID. The problem I ran into, though (I think) is that the URL I’m working from is something like

http://mysite/building/Ives-Hall (building name)

rather than

http://mysite/building/7 (building ID)

This presented a problem when I tried to specify the argument in the view, because the preview only worked when I specified the building ID – not the building name.

My next thought was to make the entire page a view, using a Page display to show the core building record and then using an attachment display to look up the affiliated addendum records. That hasn’t worked either, perhaps for the same reason. I suppose this might be able to be fixed if I could just accept using an unfriendly URL, but I get the feeling that I’m missing something simple.

So – for those of you who read this blog – what am I missing?

3 Comments leave one →
  1. June 22, 2009 6:49 am

    The building is a node, right? So in that case the internal path (the original q= value) will still be node/7. Thus you can most definitely use arg(1) to get the node ID, or use it as a views argument.

    You may also be interested in this module which builds the node reference back (making it bidirectional) http://drupal.org/project/cnr

    There are three other solutions involving views you can consider.

    1. View the building node and put the addenda in a block generated by a view. Then on your argument’s configuration you want to specify “Provide default arguemnt” and “Node Id from URL”.
    2. Use view field that would let you embed a view similar to #1 into the node. (Don’t know if this would really work or if it’s a good idea. Maybe not.)
    3. Use Panels. The delegation module can be instructed to hijack the display of building nodes altogether, and you can put the node information in one pane and a view taking the same argument into another pane.

    You also have non-views options. Use hook_nodeapi to do the lookup using the SQL you suggested on $op==view: http://api.drupal.org/api/function/hook_nodeapi/6

    Good luck!

  2. Mlle. Yotnottin permalink
    June 23, 2009 1:59 am

    I was faced with the same issue except it involved multiple many-to-one and many-to-many relationships. After trying numerous node reference type modules, views configurations, custom programming, taxonomy setups and a few other non-orthodox techniques, I finally stumbled across this post on Ryan Prices’ blog: http://drupaleasy.com/blogs/ryanprice/2008/06/using-views-2-drupal-6-create-related-pages-block

    This would be the same solution Robert mentions above as the first of three possible solutions.

    Ultimately, I decided to use taxonomy to make my relations and advice from Ryan’s post to get the view I wanted.

    I have to say this technique gave me almost exactly what I needed right out of the box. 10 minutes and I was up and running.

    Mlle. Yotnottin

  3. July 6, 2009 5:51 pm

    You need to install clean url related components/exts.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: