In my recent Drupal work last week, I needed to add custom operations to the Users Custom links on user list administration pagelist administration page accessible at “admin/user/user” on a Drupal 6 site (see the screenshot on the right).

The usual suspect to get the ball rolling was hook_form_alter. I did a print_r on the $form variable in mymodule_form_alter and was a bit surprised to see a flattened array ready to be rendered (perhaps I was expecting a Drupal 7 like behavior where tables are preserved in their source form until the very last stage of rendering).

So, what should I do now I thought. I almost instantly came up with a hackish way of appending html to the last column of the render array inside mymodule_form_alter. Not satisfied with the solution, I tried searching for a more Drupal way of doing it, but none was to be found. So I went ahead and implemented the same hackish way that worked perfectly for the client.

Here’s the code that appends a link to the “Operations” column of the user list administration page in Drupal 6:

 

{syntaxhighlighter brush: php;fontsize: 100; first-line: 1; }function mymodule_form_user_admin_account_alter(&$form, &$form_state) {
$operations = &$form[‘operations’];
foreach($operations as $uid => &$operation) {
//Add your custom links here, use $uid for the current user’s id.
$link = l(‘dictations’, ‘user/’ . $uid . ‘/dictations’, array(‘attributes’ => array(‘target’ => ‘_blank’)));
$operation[‘#value’] = $operation[‘#value’] . ‘ | ‘ . $link;
}
}{/syntaxhighlighter}

If anyone has a more civilized (oops I meant Drupalized ;)) way of doing it in Drupal 6, I would love to see it.