CCK Computed Field

Last modified: September 5, 2009 - 13:28

Computed Field is a CCK module which lets you add a computed field to custom content types. You can choose whether to store your computed field in the database. You can also choose whether to display the field, and how to format it. The value of the field is set using php code, so it can draw on anything available to drupal, including other fields, the current user, database tables, etc. The drawback of this is of course that you need to know some php to use it.

Computed Field requires the content module from the Content Construction Kit.

Before you can use Computed Field, you'll need to get CCK and enable (at the very least) the 'content' module. You will probably also want to enable the other cck modules, such as 'text', 'number', 'date', etc.

To add a computed field to a content type, go to administer > content > content types, select the content type you want to add to, and click on the 'add field' tab. One of the field types available should be 'Computed', and it should have one bullet point under it, also labelled 'Computed'. If you select this, give your field a name, and submit the form, you will get to the configuration page for your new computed field.

When is the field actually computed?

If you wish to store the values in the database then you have to update or re-submit the node to compute the value of the field.

If it is not stored in the database then the value computes when the node loads and only when the node is loaded. The field will not work in views nor will it function properly if it depends on other non-stored computed fields.

 
 

Drupal is a registered trademark of Dries Buytaert.