Adding strings in CCK Computed field

Events happening in the community are now at Drupal community events on www.drupal.org.
sticky2010's picture

Hi Guys,

I have recently joined NZ Drupal Group. I am a Junior Developer and am bit stuck on something. I am hoping somebody can help me out here.

I have a field called:
field_a | Type: text
field_b | Type:computed

so in my computed field I would like to do:

if ($node->field_a[0]['value']){
$var1="some text";
$var2="some more text";

$node_field[0]['value']="$var1.$node->field_a[0]['value'].$var2";

This doesn't display anything. I tried creating temporary arrays as well to achive the same thing but that doesn't work either. I am just wondering if this is the correct way to go about doing this or is there any other better method.

Please do advise and thank you for your time. Cheers.

Comments

You need to store the value

jonathan_hunt's picture

You need to store the value into the computed field. Have you implemented your own module or are you writing PHP into the default value in field definition for field_b?
If the former, make sure you are passing node_field by reference in the _compute function (e.g. &$node_field).
If the latter, your code needs to return an array.

Thank you

sticky2010's picture

Thanks Jonathan.

Got it done. Cheers for your pointer.

New Zealand

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: