No default value displayed for Integer

TomSherlock - July 4, 2009 - 14:45
Project:Content Construction Kit (CCK)
Version:6.x-2.4
Component:number.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

I have two CCK fields: one of type Dynamic Field (6.x-1.0), one of type Integer (CCK 6.x-2.4)

for the dynamic field i have the following php code (without the php tags):

<?php
$pta_position_nid
= $node->field_position_pta[0]['nid'];
$pta_position_node = node_load($pta_position_nid);
$pta_position_weight = $pta_position_node->field_position_weight[0]['value'];
return
$pta_position_weight;
?>

for the integer in the default area i have the following php code (again, without the php tags):

<?php
pta_position_nid
= $node->field_position_pta[0]['nid'];
$pta_position_node = node_load($pta_position_nid);
$pta_position_weight = $pta_position_node->field_position_weight[0]['value'];

return array(
0=>array('value'=>$pta_position_weight),
);
?>

The first set of code displays the desired value. The second set of code displays nothing.
Does anyone see a typo? Or is the second set of code malformed?

#1

TomSherlock - July 4, 2009 - 19:01

According to this post, the default value of a CCK field only shows when a node is first being created.

If this is correct, it poses three challenges for me. First the field has been added after the node has been created (as i am still designing the site). Second the node will almost always be created before the the field is primed with a value. Third, the expected value depends on PHP code that includes the value of a previous field. The expected value is not created until after the node has been saved.

I need a different way of priming the field with a value. I can't use the Computed Field type, because there seems be a some soft of bug preventing the value from displaying. I can't use the dynamic field because it does not store the resultant displayed value in the database.

#2

TomSherlock - July 4, 2009 - 21:51

Looking at this and this

I tried using Allowed values with this:

<?php
$allowed_values
= array();
$allowed_values[] = $pta_position_weight;
return
$allowed_values;
?>

and this:

<?php
$allowed_values
= array();
$allowed_values[$pta_position_weight] = $pta_position_weight;
return
$allowed_values;
?>

No luck.

#3

TomSherlock - July 6, 2009 - 03:14

In this post, yched appears to be saying that $node is not automatically accessible. The code would first need to get the nid and then load the node. Is this still true, or has that changed? Because this appears to be different from the experience with the dynamic field.

I thought that perhaps the problem lie with the php eval code, however the eval code also resides in the dynamic field module and doesn't have difficulty accessing the fields of the node.

I'm hoping yched's comments from the previous message are no longer true, since i want to be able to display the data in a view. I thought pulling the data from one node and saving in another would allow me then to display the data in a view using a table. Otherwise i would have to create my own template pulling data from two separate nodes and looping through them to present the data together in a table-like manner. But after considering all the time, effort and research i put into trying to avoid creating the template, it may just be easier to create the template after all.

 
 

Drupal is a registered trademark of Dries Buytaert.