I have a trouble with standard image upload widget in custom content edit form.

I retrieves the edit form for specific node by this code:

$node = node_load($nid, $vid);
$form = drupal_get_form($node->type.'_node_form', $node);
return $form;

All fields are handled good, except image fields.

When I try to upload image file, and press "upload" after that, i retrieve an error message:

    Deprecated function: Call-time pass-by-reference has been deprecated in drupal_load() (line 933 of /home/rhimin/rk2/includes/bootstrap.inc).
    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'node_form' not found or invalid function name в drupal_retrieve_form() (рядок 771 із /home/rhimin/rk2/includes/form.inc).
    Notice: Undefined index: #node в menu_form_node_form_alter() (рядок 594 із /home/rhimin/rk2/modules/menu/menu.module).
    Notice: Trying to get property of non-object в menu_form_node_form_alter() (рядок 594 із /home/rhimin/rk2/modules/menu/menu.module).
    Notice: Undefined index: #node в menu_form_node_form_alter() (рядок 600 із /home/rhimin/rk2/modules/menu/menu.module).
    Notice: Trying to get property of non-object в menu_form_node_form_alter() (рядок 600 із /home/rhimin/rk2/modules/menu/menu.module).
    Notice: Undefined index: #node в ds_extras_form_node_form_alter() (рядок 191 із /home/rhimin/rk2/sites/all/modules/ds/modules/ds_extras/ds_extras.module).
    Notice: Trying to get property of non-object в ds_extras_form_node_form_alter() (рядок 191 із /home/rhimin/rk2/sites/all/modules/ds/modules/ds_extras/ds_extras.module).
    Notice: Undefined index: #node в ds_extras_form_node_form_alter() (рядок 193 із /home/rhimin/rk2/sites/all/modules/ds/modules/ds_extras/ds_extras.module).
    Notice: Trying to get property of non-object в ds_extras_form_node_form_alter() (рядок 193 із /home/rhimin/rk2/sites/all/modules/ds/modules/ds_extras/ds_extras.module).
    Notice: Undefined index: #node в ds_extras_form_node_form_alter() (рядок 207 із /home/rhimin/rk2/sites/all/modules/ds/modules/ds_extras/ds_extras.module).
    Notice: Undefined index: field_product_image в file_ajax_upload() (рядок 265 із /home/rhimin/rk2/modules/file/file.module).
    Notice: Undefined index: #suffix в file_ajax_upload() (рядок 274 із /home/rhimin/rk2/modules/file/file.module).

Comments

grgcnnr’s picture

Just ran into the same problem today, if you get anywhere with this I'd love to know about it.

hnln’s picture

same here

hnln’s picture

Colleague of mine pointed out a simple solution (I didn't know about 'files'):

Put something like this in your hook_form_alter
//ensuring the ajax upload still has all the includes
$files = (isset($form_state['build_info']['files'])) ? $form_state['build_info']['files'] : array();
$files[] = drupal_get_path('module', 'node') . '/node.pages.inc';
$form_state['build_info']['files'] = $files;

chrlvclaudiu’s picture

Your solution is working. Thanks.

m.attar’s picture

Thanks