I am attempting to create a custom source (see #2243589: Custom source fields not displayed for selected custom source for details), and after enabling my source in the field settings in the content type, I get an error that my process function can't be found, even though I have listed the file correctly in my filefield_sources_info hook implementation. I tracked this down to the following code in filefield_sources_field_process():

  foreach ($sources as $source_name => $source) {
    if (empty($enabled_sources[$source_name])) {
      unset($sources[$source_name]);
    }
    else {
      if (isset($source['process'])) {
        $function = $source['process'];
        $element = $function($element, $form_state, $form);
      }
      if (isset($source['file'])) {
        _filefield_sources_form_include($source['module'], $source['file'], $form_state);
      }
    }
  }

Basically, what it's doing is looking for the process function, and THEN including the file that is indicated in the $source['file'] value in the info hook. This doesn't seem to make much sense, since you need to include the file that contains the code before calling the function.

On a side note, I had also added my .inc file to the files() array in the module.info file, but for some reason that has no effect.

A patch is attached that simply includes the specified file before trying to call the function.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wonder95’s picture

After a few hours trying to track down an error manifesting itself in Field Collection, I tracked it down to another case of this exact same issue in filefield_sources_field_value().

function filefield_sources_field_value($element, &$item, &$form_state) {
  // Do all processing as needed by each source.
  $sources = filefield_sources_info();
  foreach ($sources as $source) {
    if (isset($source['value'])) {
      $function = $source['value'];
      $function($element, $item);
    }
  }
}

The error would be thrown when it tried to run $function[$element, $item), because at that point the external file had not been included.

An updated patch is attached.

wonder95’s picture

Status: Active » Needs review