DrupalDork.com was shut down on September 18, 2013. This is just a snapshot of the site as it appeared then.

Posts from July 2010

Coded vs. Configurable, and Too Many Options

(Originally posted on BrockBoland.com.)

I have always felt that a site admin should have the option to disable or change functionality without having to hire a coder to do it for them. In my early days of web development, this meant I produced pages and pages of admin options. Instead of being highly customizable for the user, these apps were just highly confusing.

Now that I'm building sites in Drupal, I'm trying to find the balance again. I typically get some Photoshop files of a new site design with a description of the content types that are needed and any custom functionality that needs to be included. I build out the site, but someone else will take on the task of maintenance after that. This means they will need to tweak things when changes are needed, so I try to make things available in the admin interface as much as I can. I avoid writing special cases into the theme's template.php file or in custom modules, and prefer to use other methods like Node Displays or Panels to implement the layout within a node (and Context for the bigger picture, of course). This is the blessing and the curse of Drupal: for any requirement, there are plenty of solutions that might be the best one.

In the project I was working on today, one content type has a group of CCK fields that the client would like to display above the node title when viewing the node in its own page. Now, even though I said I avoid doing things in code if I can, I also didn't want to install Node Display or Panels just to address this particular condition, since I didn't need them anywhere else on the site.

My first instinct was to override node.tpl.php for the content type, but that template file doesn't print the title when viewing the node on its own page. I could remove the if (!$page) check in that template and let it print the title anyway, and code an exception into page.tpl.php so that it won't print the page title if the page is of that node type, but that's kind of hacky - and again, doesn't offer any flexibility to the admin who will be managing this site once I hand it over after the initial build-out.

Ultimately, I went with the admin-unfriendly solution. In the Display Fields tab for the content type, I set that group to Exclude on the Full Node display. This prevents the group of fields from displaying on the page, but they will still be rendered and included in the node object. Then, in template.php, I added a special condition to template_preprocess_node() to add the rendered HTML to the content-top region:

if(is_object($vars['node'])) {
if($vars['node']->type == 'news_item') {
$vars['content_top'] .= $vars['node']->content['group_info_fields']['#children'];
}
}

If you asked five other Drupal developers how they would handle this, you'd probably get five different answers. It's nice to have the flexibility, but can also be a pain to figure out what's best for the situation. There's even a group on gdo for reviewing modules with similar functionality; for a great example of the too-many-options issue, see the post in that group about modules that do tabs and slideshows.

This case today was a good reminder that experience can't be beat. I can spend as much time as I want reading reviews and how-tos, but I need to actually use these different modules and become familiar with them so that I have the experience to draw on when facing a similar situation down the road.

Lullabot Module Development Deep Dive Week

(Originally posted on BrockBoland.com.)

I spent the second half of this past week at the Hotel Palomar for the advanced portion of the Lullabot Drupal Module Development Deep Dive Week. I'm still on a little bit of a nerd high: it was an interesting, invigorating, and exciting three days that left me wanting to jump right into the issue queue and start fixing stuff, testing patches, and writing modules. I can only imagine how I'd feel after a full Drupalcon. I wish I could also go to the theming deep dive week in Portland, and I would definitely recommend it to any Drupal developer who can make it: the Lullabots are great. Since I started coming down with the plague sometime Thursday, I haven't done much but lay around and drink tea since leaving the hotel last night. I still need to organize all my notes and review the presentations, and then there's a long list of links to articles and modules I want to review. Over the three days I was there, we covered:

  • Views integration
  • AHAH in Forms API
  • CCK integration
  • Securing your code
  • Using alter hooks
  • Defining your own hooks
  • Keeping content/configuration ("contentfiguration" in Eaton-speak) in code (and thus, in source control)
  • Using Drush
  • Features module
  • Writing tests with Simpletest
  • Changes in Drupal 7
  • How to contribue code

A few of these areas really caught my interest, like unit testing and contributing code back. I'm hoping I can make some time to experiment in the coming weeks, and intend to write about it here when I do (I don't have many readers, I know, but I find myself referring back to posts on here all the time when I'm trying to remember how I did something before).

Tags: