Closed (fixed)
Project:
Computed Field
Version:
5.x-1.2
Component:
User interface
Priority:
Normal
Category:
Support request
Assigned:
Reporter:
Created:
23 Oct 2007 at 21:36 UTC
Updated:
22 Apr 2008 at 20:19 UTC
I have some CCK fields defined for my content. One of the fields is a CT (content taxonomy) type field that can have multiple values, so it's something like this:
field_myctfield = Array (
[0] => Array
(
[3] => stdClass Object
(
[tid] => 3
[vid] => 2
[name] => Taxon3
[description] =>
[weight] => -8
)
[12] => stdClass Object
(
[tid] => 12
[vid] => 2
[name] => Taxon12
[description] =>
[weight] => -5
)
[7] => stdClass Object
(
[tid] => 7
[vid] => 2
[name] => Taxon7
[description] =>
[weight] => 0
)
)
)
OK, so now I am making a computed field, which needs to use the weight of the first term in the array.
Here's my problem. When I tried to enter the code to get this, using the "reset" PHP function, I am getting an error that the value is "not an array" ... when it obviously is. Here is my code:
$sortnum = 0;
$items = $node->field_myctfield[0];
$item = reset ($items);
if ($item->weight) {
$sortnum = $age->weight + 8;
}
$node_field[0]['value'] = $sortnum;
This code works fine when I run it in the devel module code snippet box, but it does not work in computed field. What am I doing wrong? And more to the point, how do I get at that "first" value?
Comments
Comment #1
leeksoup commentedI still don't know the answer to this, but I found a workaround so I thought I'd post in case it can help someone. I just save the node first and then use the taxonomy API function taxonomy_node_get_terms_by_vocabulary to get the terms I need.
Comment #2
Justin Freeman commentedThe solution here is to save the node first. This is required for the taxonomy functions to work. See http://drupal.org/node/149232