CCK

Nodereference views and dynamic argument

When using views as filter and need a dynamic argument set you can't use autocomplete widget type because it uses a pre-default value that you cant change in form_alter or after_build.

If you change the widget to Select list then you can use both form_alter and after_build to set the advanced_view_args item based on arg etc.

Same goes for using PHP field in views to set a default PHP based argument, it can't get the arg list you like to have (node/[nid]/..). The arg list looks like this when using autocomlete and PHP filed:

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;
}

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

Labels for CCK single on/off checkbox field aren't appearing - some solutions

One solution of the missing labels for CCK single on/off checkbox field is to allow Unlimited values, even if you only have one value to choose. For instance if you have CCK field "Auto publish" and you want one checkbox with the label "Auto publish" and the value besides the checkbox, like "Yes". One drawback of this is that the value don't appear on edit page...

Pages