CCK Computed Field

Last modified: March 12, 2009 - 18:12

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 (cck).

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??

pjsz - February 20, 2009 - 05:08

Trying out this module. It sounds great. The question is When is this field computed and when is it retrieved from the database? Here is what I know. I need to confirm and test a bit more:

1) To use this field in a view it has to be set to store in the database.
2) When you create the field in CCK, it does not compute existing nodes and put them in the database.
3) Creating a new node it computes the field and stores in the database.
4) (Need to confirm) Updating a Node it computes the field and stores in the database.
5) Viewing a node or teaser, if stored in database it does not compute the field, otherwise, it does.

Correct

seaneffel - March 12, 2009 - 19:27

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 store 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.