Web Design, SEO and Web Applications Development

drupal

Checking if a user has a given role in D6

Drupal's API doesn't contain any ready-made function to check if a user has a certain role. While it's certainly easy enough to do, it can take a moment to figure out initially. Here's a little function that demonstrates how to do it. It isn't itself particularly useful since checking for roles is trivial without it, but it should serve as a point of demonstration.

Changing the 'redirect' value of a Drupal node form in D6

Generally, when you want to change the location that a for redirects to after submission, you usually should set $form_state['#redirect'] within a call to hook_form_alter().

<?php
/**
* Implementation of hook_form_alter
*/
function custom_module_form_alter(&$form, $form_state, $form_id) {
  if (
$form_id == 'node_type_form') {
   
// Set form redirect
   
$form['#redirect'] = some/other/path;
  }
}
?>

Unfortunately, that doesn't work for the node form. The node form has three submission buttons ('Submit', 'Preview', and 'Delete'), and each of these has it's own submission handler which sets the redirect value. Furthermore, the redirect values set in the submission handlers associated with the buttons overwrite $form['#redirect'] as set in the code example above.

Solution to CCK Field Groups not appearing in hook_form_alter()

One issue that I recently came across with a module I was editing was that the fieldsets / field groups from a CCK type weren't in the $form array passed to hook_form_alter().

According to Andy Chase, In CCK for D5 & D6, the 'fieldgroup' module supplied with CCK is given a weight of '9', which means that it's hooks will be run after most other modules.

Balance Tracker and Maintaining a Community Module

It's been almost a full month since Balance Tracker was released to the Drupal community, and I think it's probably about time to mention it on our website, and try to provide a look into our experience maintaining a community module.

Balance Tracker is a module we wrote to handle user earnings and payouts for a client. The client had a website which paid a commission to users based upon sales, and they needed a way to track how much each user earned in commission, and to track when each user was paid out.

Why we use Drupal

Over the last couple of years, our development approach has shifted considerably. When we originally began doing client work, we regularly used a fairly wide variety of tools (Wordpress, custom apps in PHP, Ruby on Rails, or Java enterprise) in addition to Drupal to accomplish our clients' wide variety of projects.

Since the release of Drupal 5 & 6, we've seen the Drupal project mature into a very capable general purpose tool. As a result, we've transitioned away from having a large toolbox of languages and tools to use on a given project, to building most of our projects on Drupal.