How can you ensure that the code for a computed field only executed after values it depends on have been entered.

I am trying code like this

if ($node->field_a[0]['value'] = ''){
$node->field_a[0]['value'] = $node->field_b[0]['value'];
}

but it appears that when the code is executing $node->field_b[0]['value'] is not yet defined.

Is there a way to ensure that the computedfield code is only executed after all the requisite values have been filled, ie after the submit button has been pressed for instance, and all user entered values have been assigned?

/voipfc

Comments

whatistocome’s picture

I'm also wondering this.

In my case the visitor can upload a different spreadsheet via a CCK "file" field type. A computed field uses a bit of PHP to read and store the number of rows in the new spreadsheet. Slick as snot when it works but after the visitor clicks Submit either a) the computed field tries to locate the OLD file and errors out, b) doesn't error out but retains the OLD count or c) works perfect.

Vote_Sizing_Steve’s picture

I'm having the same problem - (and since my firebug/watchbug is not 'firing' to help me debug,) I'm wondering how my computed field is interacting with the preceding file upload field.

My hunch is that the uploaded file is being stored in a temporary location although its [ 'filepath' ] reports it already being in the storage location... and my unpacking code is not finding the file. Re-editing/saving seems to work, but it's not as elegant as I'd like.

Vote_Sizing_Steve’s picture

Here a little function I wrote to help debug computed fields:

function Fire_Print_Delayed( $Item = '', $Optional_Title = '' ){
  $_SESSION[ 'Delayed Firebug Message' ][ $Optional_Title ] = $Item ; }

... and then call this code when page loading (currently from my own custom module):

if( $_SESSION[ 'Delayed Firebug Message' ]){
  foreach( $_SESSION[ 'Delayed Firebug Message' ] as $Title => $Item ){
    firep( $Item, $Title ); }
  unset( $_SESSION[ 'Delayed Firebug Message' ]); }

... this allows me to see firebug output when saving nodes with computed fields - placing Fire_Print_Delayed(...); in the computed field code.

Vote_Sizing_Steve’s picture

Version: 5.x-1.2 » 6.x-1.0-beta4
bkosborne’s picture

Anyone make any progress with this? I'm using a computed field to upload a CCK filefield file to an external FTP server. The $node object correctly populates with the filepath of the file, but the file clearly isn't there yet. I guess the function that actually moves the file to that actual location fires AFTER my compute field code... hmm

dqd’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Due to the Drupal core life cycle policy and security support advisery, Drupal 6 is no longer supported. So issues for Drupal 6 cannot be longer maintained. The project maintainer has asked for closing all D6 issues to clean up the issue queue. Feel free to reopen the issue if required or set it to "needs to be ported" and latest D8 dev version, if the issue discusses a still missing feature which can be implemented in the D8 version.