Drupal 6 Upload Module Reference Warnings

16th May 2011 - 4 minutes read time

I was testing out a new Drupal project build and found this strange error when uploading files to nodes using the Upload module. This error produced a lot of warning messages that appeared on the screen (in the process alarming my project manager) but appeared to have no impact on the actual function of the module, or the file uploaded. Essentially, when a file was uploaded the following errors were produced.

  1. warning: Parameter 2 to og_user_roles_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
  2. warning: Parameter 2 to customerror_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
  3. warning: Parameter 2 to date_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
  4. warning: Parameter 2 to date_timezone_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
  5. warning: Parameter 2 to location_node_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
  6. warning: Parameter 2 to og_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
  7. warning: Parameter 2 to wysiwyg_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
  8. warning: Parameter 2 to searchfilter_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
  9. warning: Parameter 2 to og_access_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.

Note that this list will vary wildly depending on what modules you have installed.

After doing a bit of searching about on the internet it appears that this is an issue left over from the days of PHP 5.2 and that this error has only started to appear now that I use PHP 5.3 on a regular basis. The problem is that the upload.module passes "array()" as one of the parameters to drupal_alter(), which in turn passes it on to anything that currently hooks into the displayed form. This causes the error to look like it is coming from multiple other modules, rather than upload itself.

The solution is to alter the /modules/upload/upload.module file so that it doesn't pass the array() parameter. This is the code from the upload.module file that causes this error.

  1. // Render the form for output.
  2. $form += array(
  3. '#post' => $_POST,
  4. '#programmed' => FALSE,
  5. '#tree' => FALSE,
  6. '#parents' => array(),
  7. );
  8. drupal_alter('form', $form, array(), 'upload_js');
  9. $form_state = array('submitted' => FALSE);
  10. $form = form_builder('upload_js', $form, $form_state);
  11. $output = theme('status_messages') . drupal_render($form);

Change this code to be the following, the major change is to the drupal_alter() function call.

  1. // Render the form for output.
  2. $form += array(
  3. '#post' => $_POST,
  4. '#programmed' => FALSE,
  5. '#tree' => FALSE,
  6. '#parents' => array(),
  7. );
  8. $empty_form_state = array();
  9. $data = &$form;
  10. $data['__drupal_alter_by_ref'] = array(&$empty_form_state);
  11. drupal_alter('form', $data, 'upload_js');
  12. $form_state = array('submitted' => FALSE);
  13. $form = form_builder('upload_js', $form, $form_state);
  14. $output = theme('status_messages') . drupal_render($form);

This is all detailed in the support request on Drupal.org at http://drupal.org/node/925580, along with a patch that will allow to make these changes automatically. It looks from the support request that this didn't make it into Drupal 6.20, but will hopefully make it into the next update.

This problem was recently (January 2011) fixed in the CCK module, and the method used in the patch was initially created to solve the same sort of problem in that module.

Comments

Permalink

Thanks ...Thanks ...Thanks ...Thanks ...Thanks ...

Kyke (Fri, 06/10/2011 - 22:43)

Permalink

Thanks. It works for me on 6.22

Remains to be seen how to solve my

The selected file blablabla.pdf could not be uploaded. The file is 206.18 kB which would exceed your disk quota of 10 MB.

issue. Anny suggestions or ideas?

David (Fri, 01/20/2012 - 17:46)

Permalink

I think you have exceeded your disk quota, which is 10MB. I would get onto your hosting provider...

Add new comment

The content of this field is kept private and will not be shown publicly.