Download & Extend

cck text field not displaying with visible checked and editable unchecked

Project:Workflow Fields
Version:5.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:infojunkie
Status:closed (fixed)

Issue Summary

I've created a content type with one cck text field and a workflow with only the creation state. Under this state the author is checked for visible, everything else is unchecked, including the editable ones. The cck field also has a default value assigned to it.

I have applied this patch to workflow. http://drupal.org/node/161190

When I go to create a new node, the field does not show up. From what I can see the problem starts on line 196 in the workflow_fields.module.

$node_field = isset($node->$key) ? $node->$key : array();

This line returns FALSE.

Here is what is in our $form['#node'] and $node :

$node Object of: stdClass
uid (string:2) 30
name (string:4) myname
type (string:8) mycontenttype
created (int) 1204919456
date (string:25) 2008-03-07 15:50:56 -0400
comment (string:1) 0
status (boolean) true
promote (boolean) false
sticky (boolean) false
revision (boolean) false

We are using Drupal 5.2. Any thoughts ?

Thanks

Comments

#1

Assigned to:Anonymous» infojunkie

To display the field as read-only in the node's edit form, I read its value (in the line that you mention) and then pass it to a function that renders it, as the CCK would render it. In your case, what does $node_field hold? In the debug listing of your node, can you see the name of your CCK field?

#2

$node_field is an empty array

When adding a new node, the CCK field is held in $form[field_myfield] and contains :

field_myfield Array [3]
#tree (boolean) true
0 Array [1]
value Array [7]
#type (string:9) textfield
#title (string:7) myfield
#default_value (string:4) test
#required (string:1) 0
#description (string:0)
#maxlength null
#weight (string:1) 0
#weight (string:1) 0

Everything works fine when editing an existing node, the only problem is when creating a new node. When creating a new node, if I have visible checked and editable unchecked for the author in the creation stage, then the form should show me the CCK field's default value as read only, correct ?

Thanks

#3

First of all, thanks for this very useful module which IMHO should be integrated in CCK (or core now that some of CCK is migrating to core).

I believe the issue I described in #254601: Cannot set and save the value of a read-only User Reference has in fact the same cause.

After some code investigation and debugging, I was wondering: is statement at line 192 (ditto line 186) in function workflow_fields_node_form_alter($form_id, &$form) of workflow_fields.module correct?

<?php
        $form
[$key.'_default_value'] = array(
         
'#type' => 'value',
         
'#value' => $form[$key][0]['value']['#default_value'],
        );
?>

$form[$key][0]['value']['#default_value'] seems not compatible with the CCK field structure (at least in some cases): e.g. in the case of a CCK user reference field, the CCK field structure is
$forms[$key]['uids']['#default_value'][0]. I had a quick look at other CCK types, and found a similar issue.

This seems especially important in the case of the "(creation)" state. The workflow_fields module is restoring the form in it original state just before form submission (function _workflow_fields_node_form_submit_creation), so that the Forms API can construct and store the intended $node data, but since the temporary form field $form[$key.'_default_value'] now contains null instead of the intended #default_value, the consequence is that is always null at creation time.

Note:
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

#4

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

#5

(talking only for comment #3 and therefore not taking ownership of or changing this issue)

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. See also related #308359: Cannot validate CCK fields passed to hook_nodeapi

#6

@pete-drupal, thanks for your feedback.

#7

Status:active» fixed

Marking as fixed unless anyone minds.

#8

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

nobody click here