(Note: I would love to upgrade to D6, but I'm still stuck with D5 because of module dependencies. So, upgrading is unfortunately not yet an option)

Symptoms
When the workflow_fields module is enabled, read-only CCK fields contained in $node data passed to hook_nodeapi ($op=='validate') are 'null' and cannot therefore not be validated by other modules.
When disabling the workflow_fields module, validation and storage succeed, but fields are of course all visible and read-write, which is not the intention.

Analysis
I think I can see what the workflow_fields module is doing: at form preparation time (form_alter) it alters the form to remove invisible fields, and to replace the #value of read-only fields with markup code that would be generated when viewing the node field. These alterations however cause the Forms API to 'null-ify' the corresponding raw data in the $node structure. The workflow_fields module is restoring the form in it original state just before form submission, so that the Forms API can construct and store the intended $node data.

The problem is that the $node data may in some cases be used after form preparation and before the actual submission: e.g. during node validation in the nodeapi($op='validate') function, causing validation to fail because of the missing field values. This also causes validation problems in other modules such as wf_required_fields.

To reproduce
Put a conditional debug breakpoint on the function workflow_fields_nodeapi in workflow_fields.module on $op=='validate'. Observe that CCK fields protected using the workflow_fields module are no longer available for validation purposes.

Possible solutions
Just brainstorming; I'm not sure whether any of the following ideas would even be adequate.

  1. Restore the CCK fields using the logic in the function workflow_fields_node_form_submit during an earlier stage than node submission. Possibly during nodeapi($op=='validate') but before the nodeapi($op=='validate') of any other module.
  2. During the form preparation (function workflow_fields_form_alter), clone the altered CCK fields to some safe place in the form itself for later retrieval (don't know whether this can/should be done persistently)
  3. The form would no longer be altered using the function workflow_fields_state_form_alter, but instead a new form theming function would be responsible for the altered display logic. It would iterate over all protected fields: invisible fields would not generate HTML, read-only fields would reuse the logic used in function _workflow_fields_node_view. The form structure itself would remain preserved.

Testing environment
I tried to reproduce the problem in a minimal environment, composed of unpatched versions of:

  • Drupal 5.10
  • workflow-5.x-2.3.tar.gz
  • cck-5.x-1.7.tar.gz
  • workflow_fields-5.x-1.0.tar.gz

Enabled modules

  • CCK / User Reference
  • Workflow
  • Workflow fields

Disabled modules

  • Core optional / Color
  • Core optional / Comment
  • Core optional / Help
  • Core optional / Taxonomy

All other modules enabled or disabled as per installation defaults.

My test environment:

  • PHP 5.2.0-8+etch11 (cli)
  • Zend Engine v2.2.0
  • mysql Ver 14.12 Distrib 5.0.32

Comments

infojunkie’s picture

Assigned: Unassigned » infojunkie

Can you please try the latest 5.x-1.x-dev because I radically changed the field handling mechanism.

pete-drupal’s picture

Version: 5.x-1.0 » 5.x-1.x-dev
Assigned: infojunkie » pete-drupal

Hello Karim. Thanks a lot for your suggestion. I just installed 5.x-1.x-dev and first testing seems to be successful. I will test version 5.x-1.x-dev extensively - as this is the last issue before my site can go live - and will confirm the status in the coming days.

pete-drupal’s picture

Assigned: pete-drupal » Unassigned
Status: Active » Closed (fixed)

Hi Karim. I have tested the 5.x-1.x-dev version with success.

Version tested: Workflow Fields 5.x-1.x-dev (2008-Aug-29)

Thanks for your help.