Closed (fixed)
Project:
FileField
Version:
6.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
28 Mar 2009 at 03:33 UTC
Updated:
12 Apr 2009 at 02:00 UTC
Hi,
I'm attempting to be able to serialize a node, along with any filefield / imagefields attached to the content type. This is similar to node cloning, but the nodes don't really exist. My thinking is this:
However, I can't seem to get my #submit function to be called. Looking through the filefield code, I don't see an easy way to override how it handles saving a file in some other "CCK-blessed" way.
Here's the snippet of what I'm trying to do:
$content_type = content_types($node['type']);
$image_fields = array();
// Find all the image fields
foreach ($content_type['fields'] as $data) {
if ($data['type'] == 'filefield') {
$file_fields[] = $data['field_name'];
}
}
foreach($file_fields as $key) {
$form[$key]['#submit'][] = '_skeleton_test_submit';
}
function _skeleton_test_submit($form, &$form_state) {
// My submit handler goes here and unsets the field from $form_state when done.
}
Any suggestions? Or am I just asking for filefield to blow up in my face? :)
Thanks!
Comments
Comment #1
quicksketchThe primary problem here is that #submit only works two things: the form itself (#type = 'form') and on buttons (#type = 'submit'). Putting submit properties on elements themselves won't have any effect.
I'm not sure when you intend this serialization to take place (or even why you're wanting it to take place). You might look at how the node_form_submit_build_node() function works, which could be helpful in generating a pseudo-node based off the current form state.
Comment #2
deviantintegral commentedAh, that would do it. So I'd have to bind to the 'upload' and 'remove' buttons instead.
The background is enabling filefield to work with the Skeleton Outlines module. It lets you create an outline of pages for a book, and then copy them into nodes to start as a template for a new book. It doesn't create actual nodes for templates; instead it hijacks the node form and serializes the values. When you create a copy of an outline, it unserializes the node and runs it through drupal_execute(). This works great for other CCK fields, but fails quite horribly on filefield (and core's upload too).
I will look at the function you mentioned and see if it helps. Thanks!
Comment #3
quicksketchMarking fixed, since I think the question about the #submit property should be answered.