Node object not fully populated?

BorisB - June 15, 2009 - 09:33
Project:Computed Field
Version:6.x-1.0-beta2
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

Seems that $node object for use in computed code isn't fully populated, especially node extensions created by other modules, like taxonomy or upload module. There should be two arrays $node->files and $node->taxonomy, but in computed code they aren't existant. Example:

Computed code is $node->field[0]['value'] = sizeof($node->files); results in "0"

Computed code is $node->field[0]['value'] = var_dump($node->taxonomy); results in "NULL"

However, these objects exist in the corresponding field template and can be displayed, devel module shows them, too, but there's no way to store them in database e.g. to use them with VIEWS.

I can't use node_load in computed code, this would result in a loop. So what can I do?

Regards,

Boris

#1

BorisB - July 8, 2009 - 19:23
Title:Node object not fully populated?» Temporary Solution

As I have to continue my work, I've no choosen to use the following workaround:

I'm using Computed Fields only on node display, and do all calculations in the field templates. CF is only an empty dummy for creating these templates, fields are always created with standard settings.

When needing calculated fields together with VIEWS, I'm now using the VIEWS_CUSTOMFIELD Module, http://drupal.org/project/views_customfield. There I can use individual php code, and via node_load there's access to the full node object.

Fortunateley it's not necessary for me to store computed values in the database.

As for me, this works for the moment.

#2

BorisB - July 8, 2009 - 19:23
Title:Temporary Solution» Node object not fully populated?

#3

ositoblanco - August 20, 2009 - 14:25

Workaround for Taxonomy:

To access the taxonomy terms use this code for the computed field:

<?php
$terms
= taxonomy_node_get_terms($node->nid);
foreach (
$terms as $key => $term) {
  if(
1 == $term->vid) { // if you only want terms from vocabulary vid == 1
   
$node_field[0]['value'] .= empty($node_field[0]['value'])? '' : ' ';
   
$node_field[0]['value'] .= $term->name;
  }
}
?>

#4

Aren Cambre - September 11, 2009 - 02:29

This may be related to #574346: Unstored fields not compatible with Views, but my request is a little different.

 
 

Drupal is a registered trademark of Dries Buytaert.