Drupal 6.x

Some Drupal links for developers

Some good Drupal developer guides or reference pages

Forms API

CCK

Views

Theme

How to set read only on an CCK autocomplete field

This is how to set an attribute like read only on a CCK autocomplete field programmatically. You have to add a after_build function to execute the below code

<?php
/**
* After build function
*/
function content_log_after_build($form_element, &$form_state){
$form_element['field_l_reference'][0]['nid']['nid']['#attributes']['readonly'] = 'readonly';
}
?>

To style it

input[readonly="readonly"] {
background-color: #EEEEEE;
}

Prerender views in module to add a summary row


/**
* Implementation of hook_views_pre_render().
*/
function mymodule_views_pre_render(&$view) {
if ($view->name == 'myview') {
// perform calculations on each row
$pointsEarned = $pointsPossible = 0;
foreach($view->result as $submission) {
if (is_numeric($submission->node_data_field_pointsearned_field_pointsearned_value)) {
$pointsEarned += $submission->node_data_field_pointsearned_field_pointsearned_value;
$pointsPossible += $submission->node_node_data_field_pointspossible_field_pointspossible_value;
}
}

How to remove preview button programmatically

This is how you can remove the Preview button programmatically on all node forms in a form_alter hook.


<?php
//in form alter hook

       //Removes preview button on all node forms
   
if(stripos($form_id, "node_form") > 0) {
      unset (
$form['buttons']['preview']);
    }

//or a specific form...

        //Removes preview button on a specific form
   
if(stripos($form_id, "[my-node-type]_node_form") > 0) {
      unset (
$form['buttons']['preview']);
    }
?>

How to make a validation and a calculation on CCK multiple field

This is how you can add validation and a calculation on a CCK field programmatically. i have a CCK field (integer) with unlimited number of items allowed. User can add the time in different formats and I have a restriction on min 15 minutes. The allowed format is:

[numeric]h[numeric]m like 3h15m

[numeric]h like 2h

[numeric]m like 45m

[numeric] like 60

Pages