So the new CCK has this nice concept of using standard, reusable form elements instead of custom widgets. That's very cool, but doesn't work as well as it could with my reusable duration form element which returns a PHP object. Getting CCK to convert this to an "item format" (an array holding three properties) was kinda hard: I needed to insert code like
if (is_object($item)) {
$item = array('duration' => $item, 'iso8601' => $item->toISO());
}
into various places. Those places being: hook_field() with $op being either of 'presave' or 'sanitize', and also hook_widget() because it directly takes the form values as $items, which is not what I would expect considering that the "item format" is used everywhere else. I was not able to persuade CCK to pass the same (itemized) format for all those callbacks, so if my widget doesn't return an array by itself then I can't rely on any consistent format.
I suggest introducing a new optional hook that transforms the submitted form value from $form_state['values'] into the CCK field's item format. If that hook is not implemented, the form value is the item format (and the code path stays the same), whereas if it is implemented then it's called in all places where form values are stored into $items. Name might be something like hook_content_item_for_form_value(), or whatever.
Thoughts?
Comments
Comment #1
jpetso CreditAttribution: jpetso commentedAlso note that calling a form_set_value() in hook_field($op='validate') is not an option, because I haven't got the $element at that time. It's still an option to create a CCK-specific wrapper element for the reusable element, but I don't find that option very compelling really.