Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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
Comment #1
whatistocome CreditAttribution: whatistocome commentedI'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.
Comment #2
Vote_Sizing_Steve CreditAttribution: Vote_Sizing_Steve commentedI'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.
Comment #3
Vote_Sizing_Steve CreditAttribution: Vote_Sizing_Steve commentedHere a little function I wrote to help debug computed fields:
... and then call this code when page loading (currently from my own custom module):
... this allows me to see firebug output when saving nodes with computed fields - placing Fire_Print_Delayed(...); in the computed field code.
Comment #4
Vote_Sizing_Steve CreditAttribution: Vote_Sizing_Steve commentedComment #5
bkosborneAnyone 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
Comment #6
dqdDue 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.