CCK does execute "process form values" three times for a widget:
- on node validation
- on node preview
- on node submit

That's probably because the changes to $node aren't persistent during validation, but that's no need for running "process form values" twice - that's for what form_set_value() is for.

Attached is a patch which removes invocation of "process form values" on node preview and submit, but makes changes to the field's data persistent on node validation through using form_set_value().

I've tested this with the date module (which uses "process form values", and it did work fine for me.
I've also tested a date field inside a fieldgroup - that also worked.

Comments

karens’s picture

I've noticed before that a number of hooks are probably called more often than they need to be, so I'm not really surprised and this is probably the right thing to do. I don't have time to test it right now but will try to get back later if no one else does.

Did you test whether previews still work? That was the reason for adding the 'process form values' to the 'view' op.

fago’s picture

yep, I've tested it. It worked fine for me.

yched’s picture

minor :
- there is a seemingly unneeded $widget_types = _content_widget_types(); line in _content_validate_save_field_values
- the function should probably be renamed _content_validate_set_form_values or something. "save" is misleading.

more importantly, the problem with _content_validate_save_field_values is that I don't think you can be sure to find the right form element in $form[$field['field_name']]. It's the general case, but that really is up to the widget to define it's form structure, so only the widget know for sure...

The best way would probably be to defer the form_set_values inside the 'validate' and / or 'process form values' ops (meaning they should be able to receive the $form argument), but I'm not sure there's a nice and backward compatible way of doing this...

fago’s picture

StatusFileSize
new3.15 KB

I've corrected your minor points. Attached is a new patch.

about finding the right form element:
I don't know if there are any widgets that behave different, I don't know any.

Further in _content_widget_invoke() the $node_field is calculated that way:

$node_field = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();

and this is intended to be the data of the field, or?

ray007’s picture

I didn't yet test the patch but just wanted to note, that the hook_widget() is still called twice with $op = 'process form values' on submission of data.
Guess I'll work around the issue by using a static variable for now ...

Anonymous’s picture

This is still not fixed in 5.x-1.6-1.
Please let me know the status of this issue.

Content taxonomy module together with TAC is facing a serious bug related to this, see http://drupal.org/node/202039.

Any updates highly appreciated!

Thanks, Joep

summit’s picture

Category: task » bug

Hi,

Is this fixed in 1.9?
Greetings,
Martijn

karens’s picture

Status: Needs review » Closed (won't fix)

The D5 version is no longer being supported. Sorry.