Drupal, urls, the difference between things and filters, and keeping urls constant

Disclaimer: The worst bit about this lesson is that, as I have written this note, I have realised that what I had planned to be the lesson was incorrect! Anyway, I will post this anyway because I may need to remember all this next time.

Todays Drupal lesson: Keeping things and filters seperate. It's going to apply to any kind of social media site, but this is a little Drupal specific note.

When you create a url structure for a "thing", in Drupal it's a node of a specific type, be it an article, a profile, an image - any stand-alone entity on a site, it's good to make sure that the URL makes sense. Today we turned on our School of Everything scrapbook. It's simple right now, just letting you create one element, a "note", but how we decide to assign a url to each note has a significant impact on how we can add more types in the future.

After various back and forth, we chose to make assign each note it's own url within a top level "/notes". For a long while we were planning to put the notes below a scrapbook in the url structure, but, not only did this end up creating really complex urls, it also added some kind of complexity in that our scrapbooks are filters. Ok, that is not too clear, lets explain a bit more.

Each of our users now has a "scrapbook", a kind of blog. The url for each scrapbook is /person/[username]/scrapbook , so mine is at http://schoolofeverything/person/greenman/scrapbook. If you want to look at the scrapbook for a subject, you can add the subject on the end, /person/[username]/scrapbook/[subject], so my Drupal notes are at http://schoolofeverything/person/greenman/scrapbook/drupal. It's a filter, in Drupal, it's build with a view. That is the easy bit (well, actually there were a few iterations to that one), the real issue came up with where do the notes "go".

Notes are not actually the best example. They are very simple and could have fitted in in many places. They are however the first of many content types for the Scrapbook, so we needed to get this right. Plan one was to put them at /person/[username]/scrapbook/entry/[nid] . I thought this worked, but Andy felt the "entry" was unnecessary. We looked at /person/[username]/scrapbook/[nid] , but I avoided this because the [id] slot is a wildcard, and it could clash with our [subject] filter. I was afraid that we would run into trouble with subjects and node ids. Eventually I realised I was wrong, and that this did not matter - last week I wrote a module that aliased our taxonomy terms, which meant that we could assume that a numeric id was not a subject. (This is the point where I went back and entered the first paragraph.)

Anyway, eventually we moved notes to a top level /note url because this sets the tone for future scrapbook types. When we add things like events and classes, they will not really fit below a person, and may even change owner. In this case, we don't want to change urls.

The eventual lessons: Know how to differentiate between a thing and a filter in your urls. Don't fix urls with information that might change.

Damn, that was a long way to say all that.


Add the first review

Write a review

Don't be shy, say hello. We'd love to hear from you.


[email protected]