Hiho

I'm trying to edit the title and alt values of $file before it's passed to the content.module to be inserted into the DB.
So I implemented the hook module_invoke_all('imagefield_file', 'save', $file) like this:

function mymodule_imagefield_file($op, &$file) {
  switch ($op) {
    case 'save':
      $file['alt'] = 'test 123';
      $file['title'] = 'test 123';
      break; 
  }
}

Any idea why this isn't changing the alt and title of the image to 'test 123'?

If I hack it directly into imagefield_file_insert() in imagefield.module after line 260 it works,
so there must be some problem with the passing by reference of $file (or me not getting php references). Thanks!

Comments

quicksketch’s picture

Category: bug » support
Status: Active » Closed (fixed)

This is not a bug, any calls to module_invoke_all() are run through call_user_func_array(), which passes all arguments by value. See http://api.drupal.org/api/function/module_invoke_all/5

quicksketch’s picture

Status: Closed (fixed) » Active
quicksketch’s picture

Status: Active » Closed (fixed)

The Drupal 5 version is maintenance-only at this point, so this API function will not be changed. Perhaps a hook_form_alter() on the node form would be able to do the same thing.